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

#1 2012-09-25 15:47:38

MKP1
New Scratcher
Registered: 2012-09-23
Posts: 4

How to clear variables when Red Stop Button is pressed?

Hi All

I have various "visible to all" variables (a countdown timer, some scoring etc). When a sprite is clicked it displays these values in a speech bubble using the "when sprite clicked" block.

I initialise my variables using "When green flag clicked" which is fine. But if I press the Red Stop button I can still click on the sprites and show the last values. In fact they are actually saved even if I close Scratch and reopen the project!

Is there any way to detect that the Red Stop Button has been pressed and clear these variables? Or should I use the workaround for the When Sprite Clicked block shown here
http://wiki.scratch.mit.edu/wiki/When_%28%29_Clicked_%28block%29 ?

In an ideal world the "when sprite clicked" wouldn't work if the Green Flag hadn't been clicked - but I can't think of any way of testing for this without using a variable (which then won't get reset when Red Button is clicked etc)...

Cheers

MKP1

Offline

 

#2 2012-09-25 15:52:32

sonicfan12p
Scratcher
Registered: 2011-11-16
Posts: 1000+

Re: How to clear variables when Red Stop Button is pressed?

Well, using the workaround is definitely an option, but it still won't reset anything. The key is to have all variables and lists reset when the green flag is clicked. There is no way to do anything after the stop sign is clicked, or stop all script is used. If it is vital to have it clear before ending, which it shouldn't be if you reset with the gf, do what Borrego6165 did in Generations4001 Gold. He made it where all variables had to be set a certain way before saving, and to do that, just press the space key. Hope that helps you some.  smile


Why are the secret organizations getting all the attention?  mad

Offline

 

#3 2012-09-25 18:19:04

MoreGamesNow
Scratcher
Registered: 2009-10-12
Posts: 1000+

Re: How to clear variables when Red Stop Button is pressed?

If the variables themselves don't matter, as long as you can't view them by clicking on the sprites, then yes, I would use the workaround.  There is no way to activate certain scripts when the stop sign is pressed.

Edit: alternatively, because the timer does not stop when the stop sign is pressed, you could have the following code instead of what you have now:

when gf clicked
forever
reset timer

when [sprite1 v] clicked
if<(timer) < (0.4)>
say the variable value
else
reset the variables
end

Last edited by MoreGamesNow (2012-09-25 18:21:16)


http://images2.layoutsparks.com/1/218929/rubiks-cube-animated-rotating.gif
"Cogito ergo sum" --  I think, therefore I am

Offline

 

#4 2012-09-25 21:13:32

BoltBait
Scratcher
Registered: 2009-03-09
Posts: 1000+

Re: How to clear variables when Red Stop Button is pressed?

This project should help you:

http://scratch.mit.edu/static/projects/BoltTest/2800099_med.png

I uploaded it to my test account.  Click the picture above to view the project.

EDIT: MoreGamesNow has a good idea. But, my method does not use the timer so you are free to use it for other purposes.

Last edited by BoltBait (2012-09-25 21:31:47)


Animated sigs must be banned!
http://boltbait.com/j.pnghttp://boltbait.com/s.pnghttp://boltbait.com/d.pnghttp://boltbait.com/a.pnghttp://boltbait.com/p.png

Offline

 

#5 2012-09-26 08:14:48

MKP1
New Scratcher
Registered: 2012-09-23
Posts: 4

Re: How to clear variables when Red Stop Button is pressed?

Oh that is really cunning - thank you!

Offline

 

Board footer