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

#1 2011-06-21 10:48:01

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Is if variable changed possible?

I need to be able to make a sprite do something if a variable is changed to anything other than what it was before it was changed. Is it possible?


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#2 2011-06-21 11:04:32

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: Is if variable changed possible?

Well, you would need two variables: the one you're using, and the past one. Have a script like this:
[blocks]
<when green flag clicked>
<forever>
<set{ pastvar }to( var
<wait( 1 )secsc>
[/blocks]

Then, if pastvar is not equal to var, do what you want. The wait can be changed to anything above 0.

Offline

 

#3 2011-06-21 11:05:43

Dinoclor
Scratcher
Registered: 2010-06-10
Posts: 1000+

Re: Is if variable changed possible?

I'll try that. Thanks  smile .


This is a temporary signature. It will exist until I think of something witty.

Offline

 

#4 2011-06-21 11:38:19

Kileymeister
Scratcher
Registered: 2008-04-17
Posts: 1000+

Re: Is if variable changed possible?

Or if you want it instantaneous, do this:
http://i53.tinypic.com/2hicqpw.gif

Put the scripts you want to be run into the empty "if" block.


I'm back, and showcasing two new* projects!  Click left or right on the image below to see!
http://img109.imageshack.us/img109/7905/part1l.pnghttp://img859.imageshack.us/img859/6417/part2bf.png

Offline

 

#5 2011-06-21 14:34:16

scratchisthebest
Scratcher
Registered: 2009-02-08
Posts: 500+

Re: Is if variable changed possible?

Kileymeister wrote:

Or if you want it instantaneous, do this:
http://i53.tinypic.com/2hicqpw.gif

Put the scripts you want to be run into the empty "if" block.

Great idea! Even better is if you put the

[set |old variable| to (variable)]

block at the top of the loop, so you don't have to put it 2 times, once in the loop and once before it.


bye 1.4, we all loved you. but we all outgrew the site. 2.0 is a welcome change.
http://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.pnghttp://scratch.mit.edu/img/Pico3-med.png

Offline

 

#6 2011-06-21 17:21:48

ASD8
New Scratcher
Registered: 2011-06-21
Posts: 15

Re: Is if variable changed possible?

scratchisthebest wrote:

Great idea! Even better is if you put the

[set |old variable| to (variable)]

block at the top of the loop, so you don't have to put it 2 times, once in the loop and once before it.

since each script runs in one frame, if u put it at the top, it wont work because it's always equal

Offline

 

Board footer