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

#1 2007-05-04 04:35:07

jstout
Scratcher
Registered: 2007-05-04
Posts: 39

A problem with for all sprites' and for this sprite only' variables

If I define a 'for all sprites' variable called b for the default cat and then define a variable b 'for this sprite only' I can't tell from the variables pane which is which although if I display them on the stage then they say b or sprite1's b. I'll call them global and local from now on.

Now define a local variable called result.

If I now change local b to 1 (so I can tell them apart) and then on the scripts pane put a
set result to b (local b that is) and run it, result becomes 1 (as you'd expect). If I change the b to be global b and run it result changes to 0 (again as you'd expect). Now drag the global b out of the set tile and leave it on the scripts pane, then delete the global b variable.

If I drag the b that's left in the variables pane (local b)  into the set tile and run it I get a result of 1 but I can still drag the b that's on the scripts pane into the set tile and run it: I get a result of 0.

This came up when a student created a bouncing ball physics simulation with a 'bouncability' (= coefficient of restitution) but made it global so every ball bounced the same way. He then made it local so he could have different types of ball, deleted his global bouncability and found that everything had a bouncability of 0.

Offline

 

#2 2007-05-04 04:41:17

jstout
Scratcher
Registered: 2007-05-04
Posts: 39

Re: A problem with for all sprites' and for this sprite only' variables

Ah ha! Once you save the project the problem goes away! That would have been interesting if I'd uploaded my project with the problem which would go away as soon as I saved it!

Still a bit disconcerting for a student, let alone a teacher. Could the shape/style of global variables be different to local ones?

Offline

 

#3 2007-05-04 10:05:28

kevin_karplus
Scratcher
Registered: 2007-04-27
Posts: 1000+

Re: A problem with for all sprites' and for this sprite only' variables

There is a very subtle color difference between global and local variables, which I did not notice until it was pointed out to me.  The distinction is much too subtle in my opinion---the "sprite1's x" used in the scoreboards is a much better labeling.

I'd also like to see the "change" and "set" blocks have a pulldown list of variables, rather than having to change blocks.  Right now if you have to change a variable name it is a major editing pain to have to find all references, pull apart the code, and put it back together.  I'd like to teach kids to use good variable names, but if changing the names is such an immense pain, I hesitate to ask them to fix things.

Offline

 

Board footer