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

#1 2012-10-12 15:28:08

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

5 kinds of variables

There should be 5 kinds of variables in scratch 2.0, each with different levels of access:

1)Cloud variables. Stored on servers and everyone playing the same project has access to the same ones.

2)Global variables. All sprites in one project have access to the same ones.

3)Sprite-local variables. Different sprites can have different local variables of the same name, but all the clones have access to the same ones. (this is how local variables work now) Also, the stage should be able to have local variables as well.

4)NEW! Clone-local variables. Every clone of a sprite gets their own copy of these variables. They start as the value of the variable in the original sprite at the time they were cloned. THERE IS NO WORKAROUND!

EDIT: This is now how local variables work anyway

5)NEW! Script variables. Temporary variables for a particular script, which are destroyed with the script ends, and different scripts can have different script variables with the same name. These would be made with a new block called "script variables" and would come with a variable in it that when you drag, the variable block does not come out of his "input", but will copy itself and the copy gets dragged instead. You could right click (or shift click) on this special "input" and rename it, and there would be + and - buttons next to it to add or remove variables. Useful if you are calculating something and you have to save parts of the calculation in order to make it work/make it fast. A script variable will cause an error if dragged into a script other than it's origin when the foreign script is run. The workaround of having lots of local variables clutters up the pallet and makes the scripts harder to read, and would fail when this sprite is cloned unless we had clone-variables.

Agree?

Last edited by joefarebrother (2012-10-15 15:48:20)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#2 2012-10-12 15:35:44

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: 5 kinds of variables

4). There is a workaround, lists, but I support.

5). When you said that the variable will be destroyed at the end of the script, what if you're using a forever block?


http://i46.tinypic.com/35ismmc.png

Offline

 

#3 2012-10-12 15:35:48

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: 5 kinds of variables

for the "clone local" variables, I can think of a workaround, as long as the "clone #" reporter exists, also I think cloning a sprite would clone the sprites local variables too
The workaround:

when gf clicked
repeat (10)
add (pick random (1) to (3)) to [list v]
end
repeat (10)
clone
end
forever
set [personal local v] to (item (clone#) of [list v])


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#4 2012-10-12 15:50:10

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

zammer990 wrote:

for the "clone local" variables, I can think of a workaround, as long as the "clone #" reporter exists, also I think cloning a sprite would clone the sprites local variables too
The workaround:

when gf clicked
repeat (10)
add (pick random (1) to (3)) to [list v]
end
repeat (10)
clone
end
forever
set [personal local v] to (item (clone#) of [list v])

That's what I originally thought of, but what i there wasn't a "clone number" reporter? You can't keep track of it in a variable, because when it changes you've lost the identification!


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#5 2012-10-12 16:02:43

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: 5 kinds of variables

If there was no clone# block clones would be extremely limited, since they could only do things identically


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#6 2012-10-12 16:09:03

ImagineIt
Scratcher
Registered: 2011-02-28
Posts: 1000+

Re: 5 kinds of variables

Agreed

Offline

 

#7 2012-10-12 16:27:16

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

At the time of this post, there is no clone number block. We NEED either a clone number block, or clone-local variables (preferably both), or clones will be extremely limited.

Last edited by joefarebrother (2012-10-12 16:28:57)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#8 2012-10-12 16:51:20

Mokat
Scratcher
Registered: 2011-12-08
Posts: 1000+

Re: 5 kinds of variables

Support.


http://www.eggcave.com/egg/977371.pnghttp://www.eggcave.com/egg/977376.pnghttp://www.eggcave.com/egg/1005291.pnghttp://www.eggcave.com/egg/996745.png

Offline

 

#9 2012-10-12 19:37:14

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: 5 kinds of variables

this could be confusing to new users which would then defeat the purpose of scratch

clone-local variables would be useful although i dont fully know what happens with cloning. that may have even been implemented already


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#10 2012-10-12 20:11:37

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: 5 kinds of variables

Currently, if a sprite with a local variable clones, a new clone-specific variable will be created.

Offline

 

#11 2012-10-12 21:14:23

zammer990
Scratcher
Registered: 2012-01-22
Posts: 500+

Re: 5 kinds of variables

Wes64 wrote:

this could be confusing to new users which would then defeat the purpose of scratch

clone-local variables would be useful although i dont fully know what happens with cloning. that may have even been implemented already

If you're referring to 5 different variable types, agreed.
if you're talking about having a "clone #" block, I can hardly see how it would be confusing, and without it the only workaround I can think of requires very specific timing if you want clones to react the way you want them to


http://i45.tinypic.com/2ynq7nn.jpg Play now!

Offline

 

#12 2012-10-12 22:08:49

Firedrake969
Scratcher
Registered: 2011-11-24
Posts: 1000+

Re: 5 kinds of variables

4.  Use procedures.


Click the sign.
https://s3.amazonaws.com/eterna/eterna2/logo2.png

Offline

 

#13 2012-10-12 22:37:12

Wes64
Scratcher
Registered: 2011-08-19
Posts: 1000+

Re: 5 kinds of variables

zammer990 wrote:

Wes64 wrote:

this could be confusing to new users which would then defeat the purpose of scratch

clone-local variables would be useful although i dont fully know what happens with cloning. that may have even been implemented already

If you're referring to 5 different variable types, agreed.

thats what im talking about.  tongue


Experienced 2.0 Tester: Ask me questions!
Using Firefox 13.0, Flash plugin version 11.4.402.287, and Windows XP Professional.

Offline

 

#14 2012-10-13 09:03:41

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

ErnieParke wrote:

5). When you said that the variable will be destroyed at the end of the script, what if you're using a forever block?

Quite simply, the variable wont get destroyed, unless the script is stopped in some other way like stop script or stop all, or the script's broadcast getting re-broadcasted.

Firedrake969 wrote:

4. Use procedures

How would you use procedures to workaround this?


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#15 2012-10-13 11:21:07

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: 5 kinds of variables

joefarebrother wrote:

That's what I originally thought of, but what i there wasn't a "clone number" reporter?

You make it.

when gf clicked
set (clone # v) to (0)
delete (all v) of (clone vars v)
repeat (10)
  change (clone # v) by (1)
  clone
  add (pick random (1) to (3)) to (clone vars v)
end
(item (clone #) of (clone vars v)) //then, to retrieve the values
Hey, Scratch is all about making stuff simple for kids and people just getting into programming, but one big aspect of programming is coming up with practical solutions to whatever you need to do.  hmm

I agree that Scratch needs "temporary" or "local" variables, they're useful for iterators and the such. Projects tend to get quite messy if you need lots of these.  tongue

Last edited by technoguyx (2012-10-13 11:25:41)


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

#16 2012-10-13 12:20:22

projectcafe
New Scratcher
Registered: 2012-03-14
Posts: 7

Re: 5 kinds of variables

The simple variable simple used today is almost the only one that will allow Scratchers to learn the concept easily. Even it needs some tutorials (see my project).

Offline

 

#17 2012-10-13 13:09:54

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

technoguyx wrote:

joefarebrother wrote:

That's what I originally thought of, but what i there wasn't a "clone number" reporter?

You make it.

when gf clicked
set (clone # v) to (0)
delete (all v) of (clone vars v)
repeat (10)
  change (clone # v) by (1)
  clone
  add (pick random (1) to (3)) to (clone vars v)
end
(item (clone #) of (clone vars v)) //then, to retrieve the values

And how do the clones identify themselves on the list once the variable changes for the next clone?

technoguyx wrote:

I agree that Scratch needs "temporary" or "local" variables, they're useful for iterators and the such. Projects tend to get quite messy if you need lots of these.  tongue

Yeah. Either that or you try to recycle them for different scripts but then you have to end up giving them generic names like "temp" or "value" and it makes your project hard to read. Or BOTH happen.  tongue

Last edited by joefarebrother (2012-10-13 13:10:14)


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#18 2012-10-13 13:26:43

Borrego6165
Scratcher
Registered: 2011-03-10
Posts: 1000+

Re: 5 kinds of variables

i'm sure there clone-local variables, like on Panther there were.


Generation:4001 Build a beautiful city, with over 50 objects and over 10000 tiles per city! This simulates traffic, pollution, tourism, crime and more!

Offline

 

#19 2012-10-13 14:42:58

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

Borrego6165 wrote:

i'm sure there clone-local variables, like on Panther there were.

At the time I made this topic, local variables worked like the sprite-local variables I described above, that all clones of one sprite use the same variable.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#20 2012-10-13 16:42:10

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: 5 kinds of variables

kayybee wrote:

Currently, if a sprite with a local variable clones, a new clone-specific variable will be created.

It'd be nice if people read what I write. Just cause I don't have a signature doesn't mean I don't write important things.

Offline

 

#21 2012-10-13 17:10:39

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

kayybee wrote:

Currently, if a sprite with a local variable clones, a new clone-specific variable will be created.

At the time of making this topic, that wasn't what happened.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#22 2012-10-14 02:17:27

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: 5 kinds of variables

joefarebrother wrote:

kayybee wrote:

Currently, if a sprite with a local variable clones, a new clone-specific variable will be created.

At the time of making this topic, that wasn't what happened.

Let me test again...

EDIT: clone-specific variables are created when a sprite is cloned with a local variable. that's how my score works (a sprite with costumes 0-9, and clones to match a digit of a variable). where are you getting you information from, that it does not do that?

Last edited by kayybee (2012-10-14 02:25:49)

Offline

 

#23 2012-10-14 08:41:03

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

kayybee wrote:

joefarebrother wrote:

kayybee wrote:

Currently, if a sprite with a local variable clones, a new clone-specific variable will be created.

At the time of making this topic, that wasn't what happened.

Let me test again...

EDIT: clone-specific variables are created when a sprite is cloned with a local variable. that's how my score works (a sprite with costumes 0-9, and clones to match a digit of a variable). where are you getting you information from, that it does not do that?

It's what happened when I tested it before making this topic.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

#24 2012-10-14 13:53:54

kayybee
Scratcher
Registered: 2009-12-07
Posts: 1000+

Re: 5 kinds of variables

joefarebrother wrote:

kayybee wrote:

joefarebrother wrote:


At the time of making this topic, that wasn't what happened.

Let me test again...

EDIT: clone-specific variables are created when a sprite is cloned with a local variable. that's how my score works (a sprite with costumes 0-9, and clones to match a digit of a variable). where are you getting you information from, that it does not do that?

It's what happened when I tested it before making this topic.

You're a tester? Oh. Never saw you on the forum.
But it's always been the way I described, so I don't know if you we're doing something differently. Look at my project the billion button. Look inside it and you'll see that each digit has its own variable. Or my particle test. The most recent one with gravity. The gravity wouldn't work if they all had the same variable...

Offline

 

#25 2012-10-15 11:06:26

joefarebrother
Scratcher
Registered: 2011-04-08
Posts: 1000+

Re: 5 kinds of variables

kayybee wrote:

joefarebrother wrote:

kayybee wrote:


Let me test again...

EDIT: clone-specific variables are created when a sprite is cloned with a local variable. that's how my score works (a sprite with costumes 0-9, and clones to match a digit of a variable). where are you getting you information from, that it does not do that?

It's what happened when I tested it before making this topic.

You're a tester? Oh. Never saw you on the forum.
But it's always been the way I described, so I don't know if you we're doing something differently. Look at my project the billion button. Look inside it and you'll see that each digit has its own variable. Or my particle test. The most recent one with gravity. The gravity wouldn't work if they all had the same variable...

I'm not a tester, I've just read this. At some point before I made this topic I did a test and local variables worked as sprite-specific, not clone-specific.


My latest project is called http://tinyurl.com/d2m8hne! It has http://tinyurl.com/d395ygk views, http://tinyurl.com/cnasmt7 love-its, and http://tinyurl.com/bwjy8xs comments.
http://tinyurl.com/756anbk   http://tinyurl.com/iplaychess

Offline

 

Board footer