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

#1 2012-06-05 12:39:28

paul2978
New Scratcher
Registered: 2012-05-31
Posts: 13

if or forever if and why?

HI all,

Im making a game where when the player hits a red color they are pushed off from
that color, however I am confused why does it only work when using the forever if

forever if
and not using the if

if <touching color [#FF0000]?>
why does the forever part be required?




when gf clicked
if <touching color [#FF0000]?>
move (10) steps
This one doesnt work


when gf clicked
forever if <touching color [#FF0000]?>
move (10) steps
This one does.
thanks

Paul

Offline

 

#2 2012-06-05 12:47:52

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

Re: if or forever if and why?

The "if" block checks the condition only once. So, if you are touching color red when the green flag is pressed, you'll move ten steps once. If you're not, you won't do anything.
With the forever if, it continuously checks, so anytime you are touching red, you'll move.
Hope that helps!

Offline

 

#3 2012-06-05 13:07:25

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

Re: if or forever if and why?

What Scimonster said, but if you need to check multiple ifs with one script, instead of

forever if
use
when gf clicked
forever
if <whatever>
do stuff
end
if <other stuff>
do other stuff
end


Why are the secret organizations getting all the attention?  mad

Offline

 

#4 2012-06-05 13:20:34

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

Re: if or forever if and why?

To paraphrase, the

when gf clicked
if <>
   Do stuff
is almost the same thing as
 when gf clicked
forever if<>
   Do stuff 
, but if you have extra stuff after the if<> block in the first one, it is not under the 'if' condition.


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

Offline

 

Board footer