Discuss Scratch

IntCool99
Scratcher
4 posts

Variables

What is the difference between sprite only variables and all sprites
awesome-llama
Scratcher
1000+ posts

Variables

Sprite only (or “local”) variables are unique to each sprite or clone. If you create one, you'll find it doesn't show in the block menu in other sprites.

These variables are useful to keep your project organised, you may have many variables that do not need to be accessed by other sprites and these can be made local to the sprite that needs them.

Another feature is the ability to store values unique to each sprite or clone. If another sprite does have a local variable of the same name, it will be treated as an entirely separate variable, able to store something else. Clones too can do this and you'll find a major use of local variables in Scratch is to give clones IDs to be able to differentiate them. Clones when created copy the value from the sprite that created it.



IntCool99
Scratcher
4 posts

Variables

when you say that clones can differentiate themselves what do you mean?
I found a problem in my game code where it works if I set the variable at a sprite only but doesn't work if I set it as all sprites
kooqle
Scratcher
92 posts

Variables

Sprite only variables are unique to the sprite:
Sprite1's sprite only variable cannot be read by Sprite2.
An all sprites variable can be.
Your glitch

IntCool99 wrote:

when you say that clones can differentiate themselves what do you mean?
I found a problem in my game code where it works if I set the variable at a sprite only but doesn't work if I set it as all sprites
can be because another sprite is changing the value.
Hope this helps!

Scratch on, superb scratchers!
IntCool99
Scratcher
4 posts

Variables

how can variables affect clones differently when they are set to sprite only as opposed to all sprites.
chippysmall4
Scratcher
1000+ posts

Variables

IntCool99 wrote:

how can variables affect clones differently when they are set to sprite only as opposed to all sprites.
A variable set to for this sprite only will affect each clone individually, while a for all sprites variable affects all clones simultaneously.
Eg: if sprite1 has a for this sprite only variable called “hp”, and there are 2 clones of sprite1, clone1 loses 3 hp, now clone1 has 3 hp less, while clone2 has full hp, if the variable were for all sprites, clone1 losing hp would make clone2 lose hp as well.

(Highlight + Shift + Down To See The Rest Of My Signature!)
Hi! I'm Cosmic-


Stuf
| Scratch Wiki | Empty My Stuff? Click Here! | Ocular | The SCM! | Project Nexus | More On The MyStuff Bug | Advanced Topics |



chaos



e
*digital art noises*
*forum noises*
IntCool99
Scratcher
4 posts

Variables

thanks for that.
cleared up the confusion

Powered by DjangoBB