(Lowercased a word.)
m (Noted that the clones of a sprite will also activate the script when receiving a broadcast individually.)
 
(43 intermediate revisions by 25 users not shown)
Line 1: Line 1:
 
{{block
 
{{block
 
| name      = When I Receive ()
 
| name      = When I Receive ()
| image      = File:When_I_Receive_().png
+
| image      = when I receive [message1 v]
| imagewidth = 134
+
| sb        = yes
| category  = [[Control Blocks|Control]]
+
| category  = [[Event Blocks|Event]]
 
| type      = [[Hat Block|Hat]]
 
| type      = [[Hat Block|Hat]]
 +
| default    = First [[broadcast]] (alphabetized)
 
}}
 
}}
The '''When I Receive ()''' [[Blocks|block]] is a [[Control Blocks|Control block]] and a [[Hat Block|Hat block]]. [[Script|Scripts]] that wear this block will activate once the specified [[Broadcast|broadcast]] has been sent.
+
The '''When I Receive ()''' [[Blocks|block]] is an [[Events Blocks|Events block]] and a [[Hat Block|Hat block]]. [[Script]]s that begin with this block will be invoked once the specified [[broadcast]] has been sent by a calling script.
==Common uses==
+
 
[[Broadcast | Broadcasts]] are used to activate [[Script|scripts]] at certain times - for scripts to activate once the broadcast is sent, those scripts must wear the '''When I Receive ()''' block. Some common uses are:
+
If the same message is sent again while the script is still running, the script will restart without reaching the blocks at the end. Using the [[Broadcast () and Wait (block)|Broadcast () and Wait]] block can help to make a message script run over and over again.
 +
 
 +
==Example Uses==
 +
[[Broadcasts]] are used to invoke scripts when certain evaluations are met; for scripts to activate once the broadcast is sent, those scripts must wear the When I Receive () block. When a sprite activates a script from receiving a broadcast, it's current clones will also receive the broadcast and activate the same script individually. Some common uses are:
 
*Preparing a change in the [[project]]
 
*Preparing a change in the [[project]]
  
[[File:Disabling_a_project.png]]
+
<scratchblocks>
 +
when I receive [Failure v]
 +
show
 +
wait (3) secs
 +
change [color v] effect by (25)
 +
stop [all v]
 +
</scratchblocks>
 +
 
 +
*Hiding select sprites when a certain condition is met under a particular evaluation
 +
 
 +
<scratchblocks>when I receive [broadcast v]
 +
hide</scratchblocks>
  
*When a button on the menu is clicked, all the other buttons must disappear
 
 
*When a scene must be set
 
*When a scene must be set
*Effective communication with scripts or [[Sprite|sprites]]
+
 
{{Control Blocks}}
+
<scratchblocks>when I receive [next background v]
[[Category:Control Blocks]]
+
next costume</scratchblocks>
 +
 
 +
*Effective communication with scripts or [[sprite]]s
 +
 
 +
<scratchblocks>when gf clicked
 +
say [Hi!] for (1) secs
 +
broadcast [communicate v]</scratchblocks>
 +
 
 +
<scratchblocks>when I receive [communicate v]
 +
say [Hi!] for (1) secs</scratchblocks>
 +
 
 +
*Creating [[Recursion#Recursion in Scratch 1.4|tail recursion]]
 +
 
 +
<scratchblocks>when I receive [run v]
 +
. . .
 +
broadcast [run v]</scratchblocks>
 +
 
 +
*Winning a game
 +
 
 +
<scratchblocks>
 +
when I receive [win v]
 +
say [You win!] for (2) secs
 +
</scratchblocks>
 +
 
 +
==See Also==
 +
*[[Broadcast () (block)|Broadcast ()]]
 +
*[[Broadcast () and Wait (block)|Broadcast () and Wait]]
 +
*[[Broadcast]]
 +
{{Event Blocks}}
 +
[[Category:Event Blocks]]
 +
[[de:Wenn ich () empfange (Block)]]
 +
[[ja:() を受け取ったとき (ブロック)]]
 +
[[ru:Когда я получу ()]][[hu:() üzenet érkezésekor (blokk)]]

Latest revision as of 19:00, 16 January 2020

When I Receive ()
when I receive [message1 v]
Category Event
Type Hat

The When I Receive () block is an Events block and a Hat block. Scripts that begin with this block will be invoked once the specified broadcast has been sent by a calling script.

If the same message is sent again while the script is still running, the script will restart without reaching the blocks at the end. Using the Broadcast () and Wait block can help to make a message script run over and over again.

Example Uses

Broadcasts are used to invoke scripts when certain evaluations are met; for scripts to activate once the broadcast is sent, those scripts must wear the When I Receive () block. When a sprite activates a script from receiving a broadcast, it's current clones will also receive the broadcast and activate the same script individually. Some common uses are:

when I receive [Failure v]
show
wait (3) secs
change [color v] effect by (25)
stop [all v]
  • Hiding select sprites when a certain condition is met under a particular evaluation
when I receive [broadcast v]
hide
  • When a scene must be set
when I receive [next background v]
next costume
  • Effective communication with scripts or sprites
when gf clicked
say [Hi!] for (1) secs
broadcast [communicate v]
when I receive [communicate v]
say [Hi!] for (1) secs
when I receive [run v]
. . .
broadcast [run v]
  • Winning a game
when I receive [win v]
say [You win!] for (2) secs

See Also