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

#1 2011-06-07 15:25:01

rivendell
Scratcher
Registered: 2007-05-29
Posts: 24

Script re-entry inconsistent?

Scratch is designed with script re-entrace:  If the trigger (hat block like key pressed, etc.) occurs before the script is completed, the script stops execution wherever it is and starts again at the top.

However, I am seeing cases where this does not seem to be the case.  Take this simple script that launches a sprite in the direction of the mouse pointer:
[blocks]
<when[ space ]key pressed>
<point towards( mouse pointer
<forever>
<move( 10 )steps>
<end>
[/blocks]

If you hit the space key while the sprite is traveling, I'd expect it to suddenly reorient itself and start moving towards the new position of the mouse.  However, a new press of the space key does nothing.  The sprite keeps traveling in the original direction right off the edge.

However, if I use a "receive" hat and a broadcast, it does re-enter the script.  This:
[blocks]
<when[ space ]key pressed>
<broadcast[ go

<when I receive[ go
<point towards( mouse pointer
<forever>
<move( 10 )steps>
<end>
[/blocks]

does interrupt the flight of the sprite and sets it off towards the new mouse pointer position.

What am I missing here?

Offline

 

Board footer