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

#1 2007-06-07 17:18:18

JRT
Scratcher
Registered: 2007-05-30
Posts: 4

The when I receive

You have to do it seperately from all other scripts with a character meaning you have to start a chain of new blocks. I would like to stop certain scripts when I receive certail items. I can't do this, so certain parts of the game don't work out how they should. Example

When left arrow key pressed
switch to costume g2
move -50 steps

Now, you can't add a when i receive to that chain to stop the script. You can't stop the script at all in this case for what i want to do. Here's the example of what i'm looking for

When left arrow key pressed
switch to costume g2
move -50 steps
When I receive stopmotions
stop script

Offline

 

#2 2007-06-07 18:10:09

Mayhem
Scratcher
Registered: 2007-05-26
Posts: 1000+

Re: The when I receive

I think the way around this is:

Firstly, set up a variable "Stopmoving", set to zero.
In place of your "broadcast stopmotions" command, have a "set stopmotions to 1" command.

Then, split your move into several smaller steps, say of -5.  Put this inside a "Repeat 10" block.

When left arrow key pressed
switch to costume g2
Repeat 10
    if stopmotions = 1
        stop
    Else
        move -5 steps


Web-spinning Spider:  http://scratch.mit.edu/projects/Mayhem/18456
3D Dungeon Adventure:  http://scratch.mit.edu/projects/Mayhem/23570
Starfighter X: http://scratch.mit.edu/projects/Mayhem/21825
Wandering Knight: http://scratch.mit.edu/projects/Mayhem/28484

Offline

 

#3 2007-06-09 00:52:38

Graham
Scratcher
Registered: 2007-04-06
Posts: 53

Re: The when I receive

I think there should be a 'I receive' button in 'Sensing' for problems like this because I think it is kind of annoying when you have to use a variable just for that.


Mini Game heaven: http://scratch.mit.edu/projects/Graham/20856 Don't press the Button: http://scratch.mit.edu/projects/Graham/3167 and Army Ants: http://scratch.mit.edu/projects/Graham/1059

Offline

 

#4 2007-06-09 02:48:38

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

Re: The when I receive

Graham, it gets a bit complicated if you want to interrupt a running script.

There are several possible notions for detecting messages that were broadcast:
1) start new scripts, restarting an already running script if necessary.  This is what scratch currently does.

2)start new scripts, but *don't* restart already running scripts.

3)raise a flag that the message has been sent, and lower the flag again when a script has received the message.  This could be useful for sending single messages to make sure that only one script gets the message (the opposite of the current broadcast scheme).  When properly implemented, such semaphores can allow mutual exclusion of critical regions of codes, to make sure that parallel threads don't step on each other.
There is some real difficulty with generalizing this concept to a broadcast though, which seems to be what your suggestion entails.

4) Have explicit "wait for message" blocks that stop a script until a message is received.
This is quite powerful, as it can trivially implement the interactions described in (2) above:
     forever
        wait for message
        do body
Only those scripts that are actually waiting for messages would receive them.
(Of course, the "when I receive" block could continue to have their current semantics of always being ready for a message.)

Offline

 

Board footer