Hello! Do self variables and clones confuse you? Me, @intellection74, @mr.gam3r, and @Petrichor teamed up to make this tutorial! We will tell you what self variables are good for, how self works, and an overview of clones. Let's get started!
What are self variables good for for?
Self variables are good for lots of stuff including
* Spiral art
* 3Dish objects
And much more. There is also a self reference in certain "when" blocks, but after reading everything here you should understand it. I will give a simple example of using self Variables to store five unique variables in a clone using @Valgo's fast cloning method.
First, add this code:
Then, add this code:
Oh, right. They all end up being zero! Let's fix that.
Now there is the example!
If you have any questions about this part of the tutorial, tag @Petrichor.
How Self works
When you put an object in a variable bubble, it refers to that object.
If that object has clones, it refers to the main/original object, the one that is on the stage editor and was cloned.
When you use Self in a bubble, it refers to the main object, and all of the clones as well.
This code means if the main Chillanna is tapped, the Happiness will increase.
In this code, any Chillanna can be tapped.
Using certain code, you can use Self to refer to a single object. In this example, the sixth clone's happiness will be set to 50. (Ignore the other code)
So, before you dive into learning about self variables, you need to know a thing or two about using Clones on Hopscotch. When you create a clone of an object you're creating an exact copy of the original object. In this example project, we're going to make some Clones scatter randomly on the screen and turn a random color.
First, add a shape object, and create fifty clones when the game starts. Next, add a rule below the repeat block, and set the clones to a random position on the screen and a random color.
Let's see what happens!
Hm... that doesn't look right. XD What happened? Aren't the clones supposed to do exactly what the original object does? Well, only the original object does things in the rule that the clones were made in. Let's tweak that rule a bit:
And here's the result!
Yay! It worked!! How about we make all of the Clones spin once they're all created? Add the following code:
Notice how all of the clones turn, not just certain ones. You can use self values to individualize a certain clone. Keep reading to learn about self values!
If you're confused about this part of the tutorial (or anything much about the basics of clones) please tag me, @Intellection74! The spiral draw Hopscotch video tutorial has some good information about Clones, so if you don't get something you could also check that out (also, here is the example project I explained if you would like to see it) Don't be afraid to experiment with Clones. They can be confusing, but it's so fun to mess around with them and explore new things!! Have fun guys!