Wiki source code of Broadcast [message]
Last modified by admin on 2023/10/24 11:56
Show last authors
author | version | line-number | content |
---|---|---|---|
1 | (% class="box infomessage" %) | ||
2 | ((( | ||
3 | Sends a specified message to all objects and the background. Useful to communicate between objects and tell them when to do something. | ||
4 | |||
5 | [[image:broadcast2.png||alt="broadcast.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 this brick:** | ||
21 | |||
22 | [[[[image:when-you-receive-__2.png||alt="When Your Receive Brick"]]>>doc:Documentation.BrickDocumentation.BroadcastReceiverBrick.WebHome]] | ||
23 | [[Learn more ~>~>>>doc:Documentation.BrickDocumentation.BroadcastReceiverBrick.WebHome]] | ||
24 | |||
25 | ))) | ||
26 | |||
27 | (% class="row" %) | ||
28 | ((( | ||
29 | (% class="col-xs-12 col-sm-6" %) | ||
30 | ((( | ||
31 | (% class="box" %) | ||
32 | ((( | ||
33 | ==== **Example** ==== | ||
34 | |||
35 | When you tap game over, the panda will disappear. You need two objects: | ||
36 | |||
37 | [[image:broadcast__-4.png]] | ||
38 | |||
39 | This is the script for the panda: | ||
40 | |||
41 | (% style="text-align:center" %) | ||
42 | [[image:When_you_receivehide_tutorial_a.png||alt="broadcast-__-5.png"]] | ||
43 | |||
44 | And this the one for game over: | ||
45 | |||
46 | (% style="text-align:center" %) | ||
47 | [[image:When_you_receivehide_tutorial_b.png||alt="broadcast__-6.png"]] | ||
48 | |||
49 | **Note: select the same message in both bricks!** | ||
50 | ))) | ||
51 | ))) | ||
52 | |||
53 | (% class="col-xs-12 col-sm-6" %) | ||
54 | ((( | ||
55 | (% class="box" %) | ||
56 | ((( | ||
57 | ==== **Result** ==== | ||
58 | |||
59 | [[[[image:null4.png]]>>https://share.catrob.at/pocketcode/project/34643]] | ||
60 | |||
61 | [[image:broadcast__-3.gif||alt="When tapped Example"]] | ||
62 | ))) | ||
63 | ))) | ||
64 | ))) |