Trying it out - One Makes Many: Cloning

Objective

After completing this lesson, you will be able to apply the concepts of the previous lesson - One Makes Many: Cloning.

Exercise

Your Turn!

Now it’s your turn. Download this document for a recap of the blocks we covered in this lesson and some hands-on exercises for you to explore.

What You Have Learned in This Lesson

Clones

This lesson’s main topic were clones. Clones are shallow copies of the original sprite.

That means they share complex attributes such as scripts, costumes, sounds, and variables. In a "biological" sense, clones share the same "genetic material" with the organism they were cloned from (in this case that is the scripts).

However, this "genetic material" can manifest in different ways due to external conditions (in biology e.g. climate, nutrition - in computer science e.g. random values for inputs).

Programmatically generated clones share have the same values as their parent sprite for attributes like size, costume, position or graphic effects.

You can use the When I start as a clone hat block to initialize and individualize them to wear another costume, go to another position or have a different size.

This concept is called "initialization" in computer science.

You can use clones to create projects with multiple agents that behave similarly. This makes complex projects much quicker to program, because you only have to model one sprite that you can then clone as often as you need it.

Script variables

You already got to know sprite-local and global variables in previous lessons. In this lesson, you heard about a third type of variable, the script variable.

Script variables have a more limited scope; they are only valid inside the script they are defined in. Outside of that script they cannot be accessed, set or changed.

Script variables are especially useful if you just want to use them in a single script and don’t need to access their values from outside that script. In this lesson we used them to set the speed of each clone in the flower individually.

One of the big advantages of script variables is that they don’t "clutter" the palette, because they don’t get a permanent variable reporter in the "Variables" category.

You can create a script variable with the script variable _ block. Clicking on the orange variable opens a dialog box where you can rename the variable. Clicking on the right arrowhead adds further script variables.

Script variables can be renamed by clicking on the orange variable reporter. Pick a name in the “Script variable name” dialog box and click “Okay” to change the variable name.

Sometimes it is helpful to monitor variable values while your program is running. Since script variables don’t get a reporter in the palette, you can’t check the box to show the watcher. However, there’s two other ways to display their values on the stage.

You can either right-click the script that contains the script variable and select the variable name from the end of the dropdown menu. Mind you, script variables only exist, while the script they are defined in, is running.

Alternatively, you can use the show and hide variable blocks. Select the variable you want to display and when the block is executed, that variable watcher will appear on stage. To hide a specific variable, you can select it from the dropdown menu of the hide variable block. Leaving the input slot empty, will hide all temporary variables currently displayed on the stage.

A script variable can be displayed on the stage by right clicking the script it is defined in while it is running and selecting the variable name from the context menu. Alternatively, it can be shown and hidden using the eponymous blocks.