Sending a message
ReadingThings that talk to each other
So far, each character has minded its own business. A slime's script only changed that slime. But in a real game, things work together. Step on a block, and a door opens somewhere else.
For that, one part of the game has to tell another what has happened. It sends a message.
Send and listen
A message has a name, in quotes. One script sends it. Any script can listen for it.
| To | Write | It means |
|---|---|---|
| Send a message | trigger "alarm" | Tell the whole game: the alarm has gone off. |
| Listen for it | when "alarm" | Do the steps under this line when that message comes. |
The sender does not know who is listening. It just shouts. Anyone with a matching when line hears it.
An example
A block's script sends the message.
when the {Hero} steps on me
trigger "alarm"A door's script listens for it.
when "alarm"
open the {Door}The hero steps on the block. The block sends "alarm". The door hears it and opens.
Three rules for messages
| Rule | What it means |
|---|---|
| The names must match | trigger "alarm" only sets off when "alarm". A name spelled another way is another message. |
| Many can listen | One message can set off a door, three enemies and a light, all at once. |
| No one has to listen | A message that nobody hears does nothing, and that is fine. |
Finish this section
Tick Finished reading at the bottom of the page. Then press Next. Your game is about to get a second level.

