Home Lessons Apps Support About Consultations We create games Contact
Home Lessons Apps Support About Consultations We create games Facebook

Lesson 7: Sending and processing of messages.

Select the device which you develop the application for:
 

We will learn:
- How and when characters can send messages;
- How to use the command Slot[] that processes messages;
- Commands: Send, New=, Stop= .

You already know how to use the command Slot[Touch_...] that connects touch messages with appropriate states of characters. Characters can send different messages. For example, the sun rose up and sends flowers the Light message. The flowers unfold their petals. Or, a terrible monster woke up and sends the Scare message to small creatures. The small creatures begin to tremble with fear.

Start Game Pilot, select "Prepare demo project", then select the "7 Work with messages" project. Open the project.

Tap the red creature. Actually, it is a terrible monster. Let us take a look into the code of the monster character:

 

- - - - - CODE BEGIN - - - - -

Scale = 50

1: Img=1 Mp3=1 // monster sleeps
   Delay=500
   Delay=0 Send=Calm // send Calm message
   Slot[Touch_Self]=2 // if monster touched go to state 2
   Rest

2: Slot[Touch_Self] // stop slot
   Img=2 Mp3 // monster looks terrible. Stop the snore sound with Mp3 command
   Delay=0 Mp3=2 // monster growls
   Delay=500
   Delay=0 Send=Scare // send Scare message
   Delay=5000
   Delay=0 State=1 // monster sleeps again

- - - - - CODE END - - - - -

 

When we run the project, the monster is in the 1st state, he is sleeping.

In state 1, there is a command Slot[Touch_Self]=2. That means, as soon as someone touched the monster, the monster would wake up. And goes to state 2.

The state 2 begins with the line: Delay=0 Slot[Touch_Self] // stop slot

The command Slot[Touch_Self] disables the slot (note that there is no Delay command in this line because touches are always processed immediately). If we do not disable the slot and touch the monster while it is in the 2nd state, the 2nd state begins one more time. That means, all the actions of the 2nd state would be performed two times simultaneously.

There is the following line in the 2nd state: Send=Scare
The monster sends the Scare message. This message is received by the characters orange and lemon. Below is the description of the orange character:

 

- - - - - CODE BEGIN - - - - -

Scale = 50
Slot[Scare]=2
Slot[Calm]=1

1: Stop=3 Img=1 // orange smiles
   Rest

2: Stop=1 Img=2 // orange scared
   New=3 // the new parallel state 3 begins
   Rest

3: Delay=50 Angle=10 // orange trembles
   Angle=0 // orange trembles
   Delay=0 State=3 // go to begin of state 3

- - - - - CODE END - - - - -

 

As you see, there is the Slot[Scare]=2 command in the head of the file. This command connects the message with the 2nd state (orange is scared). Using the command Slot[...]= , you can connect any message from any character, with a certain state.

In the 2nd state, the orange changes its face expression (Img=2). Next line has the command New=3, that means "perform a new parallel state 3". A character can perform several states simultaneously. In our case, when the orange character performs state 3, the 2nd state rests, (because the next string in the 2nd state is Rest).

Now look what happens in the state 3. The image of the scared orange begins to slightly but quickly change the angle, as a result we see that it turns to the left and then back to the right. After each „right-left turn“ we go back to the begin of the state 3. The turns repeat over and over, so we are getting a trembling orange.

When would orange stop trembling? In the head of the .stt-file there is also a command Slot[Calm]=1. Orange receives the Calm message that brings it into the 1 state (calm state).

The Calm message, as well as the Scare message is sent by the monster character. Let us look into the code of the monster again, to see when exactly the Calm message is sent.

It is sent in the 3rd line of the state 1 (monster's sleeping):

Delay=0 Send=Calm // send Calm message

When the monster falls asleep, there is no need to be scared of him. And the monster falls asleep every time it finished to growl. You see the line at the end of the state 2: Delay=0 State=1 (after several seconds of growing, go to state 1).

At the beginning of the state 1, there is a command Stop=3, and at the beginning of the state 2 we have a command Stop=1. The thing is that when the slots (Slot[Scare]=2 or Slot[Calm]=1) open the new states, these states would open as parallel states. And the state that was performing before the new one has opened, would be still performing. To close these "previous" states, we use the commands Stop=3 (close the state 3) and Stop=1 (close the state 2).

Note that if you tap the monster during it performs the state 2, the state 2 will start one more time. This will cause all the commands to execute two times simultaneously.

To avoid it, you need stop the slot in the state 2. You can do it by adding the following string to the beginning of the state 2: Delay=0 Slot[Touch_Self] // stop slot

 

Task 1:

In your own project, create characters that send messages to other characters. For example, if the sun rises up, flowers unfold their petals and birds begin to sing. You can use your own images.

You can also use our images for experimenting (download the archive here).

If you need sounds, you can search and download some on the following site: http://soundbible.com.

Use the Send=... command for sending messages, and the Slot[...] command to connect these messages with appropriate character states.
 

- Download the archive with project files for this lesson -


Privacy Policy    Terms of Use     Copyright © Rais Garifullin