Wiki source code of When you receive [message]
Last modified by admin on 2023/10/24 11:55
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | (% class="box infomessage" %) | ||
2 | ((( | ||
3 | With this block your object listens for a specific broadcast message and then runs the script when the message is received. Useful to communicate between objects and tell them when to do something. | ||
4 | |||
5 | [[image:when-you-receive-__2.png||alt="broadcast__-2.png"]] | ||
6 | |||
7 | **Why send broadcast messages?** | ||
8 | |||
9 | With messages you can communicate and interact between different objects within a scene. It allows one object to send a message to all other objects, and the receiving objects can then react or respond to that message. | ||
10 | |||
11 | **How does it work?** | ||
12 | |||
13 | * //Sender object~:// The sender object starts the communication by using a //"Broadcast"// block. This block is used to send a message to all other objects in the scene (also the background). | ||
14 | * //Receiving object~:// The receiving object is the one that listens for and responds to messages. It uses the //"When you receive"// block to detect when a specific message is being received. | ||
15 | * //Message Handling~:// When the receiving object gets the message, it will execute all the blocks that are beneath the //"When you receive"// block. This allows you to define custom behavior or actions that occur when a particular message is received. | ||
16 | ))) | ||
17 | |||
18 | (% class="box" %) | ||
19 | ((( | ||
20 | **Correlates with these bricks:** | ||
21 | |||
22 | [[[[image:broadcast2.png||alt="broadcast.png"]]>>doc:Documentation.BrickDocumentation.BroadcastBrick.WebHome]] | ||
23 | [[Learn more ~>~>>>doc:Documentation.BrickDocumentation.BroadcastBrick.WebHome]] | ||
24 | |||
25 | |||
26 | [[[[image:brodcast_wait_brick3.png||alt="Broadcast and Wait Brick"]]>>doc:Documentation.BrickDocumentation.BroadcastWaitBrick.WebHome]] | ||
27 | [[Learn more ~>~>>>doc:Documentation.BrickDocumentation.BroadcastWaitBrick.WebHome]] | ||
28 | ))) | ||
29 | |||
30 | (% class="row" %) | ||
31 | ((( | ||
32 | (% class="col-xs-12 col-sm-6" %) | ||
33 | ((( | ||
34 | (% class="box" %) | ||
35 | ((( | ||
36 | ==== **Example** ==== | ||
37 | |||
38 | When you tap game over, the panda will disappear. You need two objects: | ||
39 | |||
40 | [[image:broadcast__-4.png]] | ||
41 | |||
42 | This is the script for the panda: | ||
43 | |||
44 | (% style="text-align:center" %) | ||
45 | [[image:When_you_receivehide_tutorial_a.png||alt="broadcast-__-5.png"]] | ||
46 | |||
47 | And this the one for game over: | ||
48 | |||
49 | (% style="text-align:center" %) | ||
50 | [[image:When_you_receivehide_tutorial_b.png||alt="broadcast__-6.png"]] | ||
51 | |||
52 | **Note: select the same message in both bricks!** | ||
53 | ))) | ||
54 | ))) | ||
55 | |||
56 | (% class="col-xs-12 col-sm-6" %) | ||
57 | ((( | ||
58 | (% class="box" %) | ||
59 | ((( | ||
60 | ==== **Result** ==== | ||
61 | |||
62 | [[[[image:null4.png||alt="Download"]]>>https://share.catrob.at/pocketcode/project/34642]] | ||
63 | |||
64 | [[image:broadcast__-3.gif||alt="When tapped Example"]] | ||
65 | ))) | ||
66 | ))) | ||
67 | ))) |