How to Copy Block Code between Characters

Today, we are focusing on a major time-saver in ScratchJrcopying entire stacks of block code between characters. This technique, combined with the Start on Tap block, allows you to quickly programme multiple characters to perform the same action, like simulating tree growth!

Our project demonstrates this by having Kitten observe two different trees growing in a spring setting.

Setting the Scene and Reusable Characters

To start, we prepare our background and add the characters that will share the same script.

  1. Change the Background: Select the spring background to set the scene. [00:21]
  2. Add Two Trees: Add two different tree characters (or any two characters you wish to programme similarly) to the canvas. [00:36]
  3. Position Characters: Place Kitten and the two trees on the screen.

Coding the First Tree: The Growth Script

We will create the interactive “growth” script for the first tree. Ensure this tree’s icon is selected.

  1. The Trigger: Go to the yellow category and add the Start on Tap block. This means the growth animation only starts when the user taps the tree. [01:15]
  2. The Wobble (Motion): Go to the blue Motion category and add a Move Right block followed by a Move Left block. This rapid, opposing movement makes the tree appear to “wobble,” simulating growth or movement. [01:22]
  3. The Growth: Go to the purple Looks category and add the Grow block. This makes the tree character bigger. [01:33]
  4. End: Finish the script with the red End block. [01:41]

The Efficiency Trick: Copying the Code

The main goal is to avoid rebuilding the exact same script for the second tree.

  1. Drag and Drop: Click and hold the entire stack of code you just created for the first tree. [01:47]
  2. Copy: While holding the script, drag it over the icon of the second tree in the bottom-left character tray and drop it. [01:55]
  3. Verify: Click the second tree’s icon. You will see that the exact same code has been copied across to its scripting area. [02:00]

Running the Interactive Project

When you tap the Green Flag (to reset) and then tap the first tree, it will wobble and grow. Then, tap the second tree, and it will also wobble and grow, demonstrating that both characters now have the same, user-triggered script. [02:06]

Mastering the technique of copying code is a huge step in our coding tutorials for teaching children code efficiency and reusability. For structured lesson plans, explore our collection of ready-made lessons. Happy coding!