Now you know how to make a character speak and move. Now it’s time to learn a proper coding trick that saves time and effort: using the Repeat block.
This tutorial shows absolute beginners how to make a character take several steps without using out multiple move blocks.
1. Preparing the Scene for Repetition
As always, we start by setting the stage for our ScratchJr programme.
- Changing the Background: For this exercise, we are moving the kitten out of the bedroom and into the great outdoors! The video instructs you to select the Suburbs background to give the kitten space to walk [00:16].
- Positioning the Character: Before coding the walk, you’ll learn to tap and drag the kitten character to a starting position, ensuring there is enough room on the screen for the action to take place [00:30].
2. The Programme: Building the Basic Movement
Before introducing the Repeat block, the tutorial builds the core action sequence.
The Fundamental Three Blocks
- The Start: Drag out the Green Flag block from the yellow section to mark the start of the code [00:43].
- The Action: Select the Move Right block from the blue section [00:50]. Crucially, this block is set to move just one square.
- The End: Finish the sequence with the Stop block from the red section [01:03].
3. Mastering the Orange Repeat Block
Here’s the clever bit. You could drag out four separate ‘Move Right’ blocks to make the character take four steps, but that’s a bit of a palaver! The Repeat block automates this, which is essential for efficient coding.
- Finding the Block: Head over to the orange control section and locate the special looping Repeat block [01:06].
- Creating the Loop: The video demonstrates how to wrap this Repeat block around the single Move Right block. The move block fits snuggly inside the loop [01:10].
- How it Works: By default, the Repeat block has the number 4 on it. This means the single ‘Move Right one square’ command is executed four times. In essence, the kitten now moves four steps with only one movement block in your sequence [01:33]!
4. Testing Your Looped Code
Time to see if this efficient beginner coding works a treat!
- Run the Code: By pressing the Green Flag, the kitten slides across the screen by four squares [01:42].
- Verification with the Grid: The video handily shows how to turn on the Grid tool. This allows you to visually confirm that the kitten has indeed moved the programmed four squares, highlighting the precision of the Repeat block [01:50].
- Reset: Remember to use the Reset button next to the flag to instantly return the kitten to its starting position for another run [01:58].
Understanding the Repeat block is paramount for any ScratchJr Coding enthusiast. It’s the cornerstone of creating longer, more complex animations without a giant sequence of blocks!
If you enjoyed this, here are more ScratchJr tutorials, projects and lessons.