When I receive ()
The -when I receive - -) block
Category Control
Type Hat
Disabling a project

"When I receive" stops a simple script

The When I Receive () is a Hat Block and a Control Block that allows sprites to listen for broadcasts sent by the broadcast () and broadcast () and wait blocks. Since there is no way to directly pass arguments through the block, it is difficult to broadcast messages intended for select sprites only.

Use with broadcast () and waitEdit

The Broadcast () and wait block sends a broadcast and pauses execution of a script until all receiving scripts that execute on the broadcast have stopped running. For this reason it is a good idea to be careful about the ways forever loops and such are used on receiving scripts.

Broadcasting to specific spritesEdit

Because Scratch 1.4 does not permit argument-passing in any form, directing a message at a single sprite is not a straightforward thing to do. However, it is fairly simple to simulate this functionality with a few global variables. These variables can store data that would otherwise be placed inside the non-existent message arguments. If an argument can pertain to only one sprite that will receive the broadcast (see Counting Sprites), then it can be targeted specifically at that sprite. For instance, a script might set a global variable like so:


Then, certain sprites listening for the "hide selected sprite" broadcast would all receive it. However, since the broadcast script is checking the global "selected sprite" variable against the sprite's "my unique number" variable, only one sprite will act on the broadcast. When I Receive