The variable self


I don't necessarily know what the variable self does can someone help me?


There's a topic for that already


I am a bit confused too, well I don't even know what a variable is.


The variable self basically means the object's... self. XD

When you want an object to do something when it has already done something, Self is what you need.

Say you want an object to grow when it touches something else. You would use the code "When (Self) touches (whatever you want it to touch before it grows) Grow by (percent)"

If you need more help, tag me :D


I can help explain it, if you want :D


Have you ever thought of being a teacher? You have good teaching skills...


Yeah, that's what I want to be when I grow up. Thank you! :D


Welcome. Seriously, dude, do it!!!!


Check @bluedogmc-official's topic.



Please do~
I've figured out how to use the "wait" command and the "jump" thing but that's about it :sweat:


I can tell you how to use it.


Sure anyone can I'd love a lot of help ~ :heart:
Don't take that the wrong way, hehe


Ok. What do you want explained? I'm in a car driving through Dallas at the moment, but I have internet.


Variables are exactly what they sound like: they're "numbers" that are variable. Meaning, they can change, or "vary." But you control what a variable changes to. This is useful for randomizers and other things.

Example! Read this!

For example, say you want something to be randomly either blue or red every time you tap a button.

First, you take your object, let's say a circle. You want it to be either blue or red when you tap a button, so you want the color to be different and change, or vary. Hey, you need a variable!

You can call variables whatever you want, let's call this one "Random." Remember that!

So, this object should vary in color at the same time as the value of the variable varies. (That's a lot of "V"s!)

We want to make the color vary when the variable varies, so we'll put "When Random=1." (you can put any number here, but 1 is easy to remember.)

This means that something will happen when the value of our variable "Random" changes (varies!) to 1.

Doesn't that sound like what we wrote earlier? All it's missing is the part where it does something (in our case, changes color)!

So, we'll code it to change color to red because we already know when it will do that. We'll simply put "Set Color" and select red or use an HSB red.

There we go! Now it will change color to red when Random equals 1.

But we want it to do that with blue, too, right? So we'll go and add a new rule. Now we put "When Random="... but we need a different number. I'll go with 2. So,"When Random=2."

Then we'll put down "Set Color" and select your blue.

But wait... we need our button, because the variable isn't equal to 1 or 2, meaning the code won't happen!

Here's where the "random" bit comes in. You're going to get another object, let's say a circle, for your button.

Now you want to do "When Self is Tapped" because you want the first circle to be red or blue when the button is tapped.

Then you'll have it make our variable vary, meaning the color of the first circle will also vary thanks to our previous code. You can do this with the code "Set Variable "Random" random 1-2", which will make your variable randomly change, meaning- the color will change!

This is just one example of the use of variables in code. If you know the concept "when variable equals (number), (something) will happen" you can do lots of new code! :D


@treefrogstudios Yes, you're right of course :smile: ...but it's more than that. The question not addressed is why do we need a (self) reference when you could just reference the object directly?

You don't need to use a (self) reference anytime "you want an object to grow when it touches something else". You could, but that's not the point. There are special cases where you have to use a (self) reference...

1) If you're using clones and want only the individual clone responding to the event to follow the coded action

2) Again with clones, if you wanted to refer to a property of the responding object. For example, if you wanted to use Set Size instead of Grow By these two blocks are equivalent

3) You want to make/use a custom block for multiple objects (that are not clones) that needs to refer to the object's properties (like if you wanted to include the Set Size above)


Yeah, I know. I was sort of giving a basic explanation :P