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

#1 2007-03-27 09:55:34

mschlager
Scratcher
Registered: 2007-03-09
Posts: 15

'broadcast and wait': 'forever if' doesn't send 'done'

An example of what I'm trying to do: One sprite with two scripts:

script 1:

when greenFlag clicked
    point in direction 0
    broadcast 'go' and wait
    point in direction 90

script 2:

when I receive 'go'
    forever if not direction=-150
        turn left 15 degrees


Problem: The last line of script 1 doesn't ever get executed.

Workaround to get this going:

script 2:

when I receive 'go'
    forever
        if not direction=-150
            turn left 15 degrees
        else
            stop script

I tend to consider this a bug.

Markus

Offline

 

#2 2007-03-27 23:14:04

paulmedwal
Scratcher
Registered: 2007-03-09
Posts: 100+

Re: 'broadcast and wait': 'forever if' doesn't send 'done'

The "forever if" block is equivalent to having an "if" block inside of a "forever" block. As shown in your workaround, only the "stop script" block will get you out of the forever loop.
http://www.paulmedwal.com/scratch/foreverif.jpg

Last edited by paulmedwal (2007-03-27 23:15:44)


clutter.scratch.mit.edu Visit the Clutter site to create multi-scene stories and multi-level games with Scratch.

Offline

 

#3 2007-04-01 14:26:15

PTT
Scratcher
Registered: 2007-03-19
Posts: 2

Re: 'broadcast and wait': 'forever if' doesn't send 'done'

I must say I find the "forever if" block a bit confusing and useless. I first thought too it was a "do while" block, which ends when the condition isn't true anymore.

Like you say it is easy assembled of only two other blocks, so I would propose to get rid of this block in Scratch. (and add a "repeat until" block, which is usable as "do while" by adding a "not", but that's already planned for version 1.1)

Offline

 

#4 2007-04-28 05:38:47

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

Re: 'broadcast and wait': 'forever if' doesn't send 'done'

If "forever if" is implemented right, it should be the equivalent of

forever
   wait until <condition>
   action

rather than

forever
   if <condition>
      action


The difference is a subtle one:  wait should only be executed when the variables that are involved in the condition change, while "if" has to be continuously evaluated (though the forever-if construct can be optimized to forever-wait.

Offline

 

#5 2009-11-15 12:31:00

ThePCKid
Scratcher
Registered: 2009-09-16
Posts: 1000+

Re: 'broadcast and wait': 'forever if' doesn't send 'done'

<forever if>
The above block is obsolete

Offline

 

#6 2009-11-15 12:33:38

Greatdane
Scratcher
Registered: 2007-06-05
Posts: 1000+

Re: 'broadcast and wait': 'forever if' doesn't send 'done'

Forever if is not obsolete. However, I tend to use
forever
     if
because it is much more flexible.  smile


The future belongs to those who believe in the beauty of their dreams.
        ~ Eleanor Roosevelt

Offline

 

#7 2010-11-18 13:03:48

axorion
Scratcher
Registered: 2010-01-05
Posts: 28

Re: 'broadcast and wait': 'forever if' doesn't send 'done'

As far as I'm concerned the forever if block is worthless. I would much rather have a block that evaluates at the bottom, forcing the code to execute at least once before exiting the loop.

kevin_karplus said:

The difference is a subtle one:  wait should only be executed when the variables that are involved in the condition change, while "if" has to be continuously evaluated.

And how does the computer know the variables have changed? Well, it isn't magic! Event driven programming only hides the evaluation process in order to make things easier on the human programmer. Trust me when I tell you that your microprocessor is still continuously evaluating every condition capable of triggering an event. Furthermore, just because a given evaluation is not associated with an event does not mean that it has not been optimized by branch prediction. And so even an if statement can wait for the values to change before doing a full reevaluation.

Last edited by axorion (2010-11-18 13:09:35)

Offline

 

#8 2010-11-18 20:16:05

hmnwilson
Scratcher
Registered: 2007-07-04
Posts: 1000+

Re: 'broadcast and wait': 'forever if' doesn't send 'done'

This topic's from 2007... I think it's time to close it.


I'm taking a break from Scratch until 2.0 comes out. Any messages sent between then and now probably won't be read - sorry.
(Oct. 20, 2011)

Offline

 

Board footer