This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-04-14 16:36:25

echristophy
New Scratcher
Registered: 2013-02-28
Posts: 17

variables question

Hi,

I'm working on a project where I want the program to list a bunch of 4-digit numbers, which each digit is a separate calculation. I set up a variable called x to store the x-position of the number, but then I realized that when I changed x for the 2nd sprite, I was changing it for the first sprite. I noticed that when I make a variable, I can make it for only one sprite. Is it possible for me to set up an "x" for each of my 4 sprites and have them not overlap or confuse myself? Or should I set up an x1, an x2, etc.? Opinions from veteran scratchers?

Offline

 

#2 2013-04-14 16:41:35

Hyperbola
Scratcher
Registered: 2013-03-15
Posts: 100+

Re: variables question

Check "For this sprite only" when making the variable


Tip of the whatever: Don't post in threads older than 2 weeks unless your post will actually be useful.
It's the last day of 1.4! *cries* (quote from NeilWest, rest by me) by the time you read this it probably will be 2.0  sad

Offline

 

#3 2013-04-14 20:17:53

OverPowered
Scratcher
Registered: 2012-07-27
Posts: 100+

Re: variables question

Hyperbola wrote:

Check "For this sprite only" when making the variable

+1. ^_^
http://i45.tinypic.com/157i5hi.jpg


Newest project: Tunnel TEST ~http://blocks.scratchr.org/API.php?user=OverPowered&action=onlineStatus~ On my mind: Unicameralism

Offline

 

#4 2013-04-14 20:26:53

CAA14
Scratcher
Registered: 2013-01-14
Posts: 1000+

Re: variables question

echristophy wrote:

Hi,

I'm working on a project where I want the program to list a bunch of 4-digit numbers, which each digit is a separate calculation. I set up a variable called x to store the x-position of the number, but then I realized that when I changed x for the 2nd sprite, I was changing it for the first sprite. I noticed that when I make a variable, I can make it for only one sprite. Is it possible for me to set up an "x" for each of my 4 sprites and have them not overlap or confuse myself? Or should I set up an x1, an x2, etc.? Opinions from veteran scratchers?

Well, there are two different types of variables in Scratch, "Global" and "Local".
If you want a certain variable to only be for one sprite, then check the "For this sprite only" check box when creating it. Even though it's now only for the sprite you created it for, other sprites can access the info, but cannot change it using the,

 < [attacked? v] of [Sprite 1 v] >
Block. The "attacked?" is an applicable scenario.  smile

You could make "Xp2" and "Xp1" both global, but they are really only needed in most cases for local stuff, so making them just "X" and local makes the most sense.  wink

Regards,

CAA14

Offline

 

Board footer