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

Lesson 6: Several states for a character. Slots.

Select the device which you develop the application for:
 

We will learn to:
- add new character states.
- use the Slot[Touch_Self] command.

We have already said that a character can perform several sequential actions. On the last lesson, we looked into this code:

 

- - - - - НАЧАЛО КОДА - - - - -

Scale = 50

1: Img=1
   Delay=2000 // wait
   Delay=100 ScaleX=55 Mp3=1// grow
   Delay=2000 // wait
   Delay=100 ScaleX=60 Mp3=1// grow
   Delay=2000 // wait
   Delay=100 ScaleX=65 Mp3=1// grow
   Delay=2000 // wait
   Delay=100 ScaleX=70 Mp3=1// grow
   Delay=2000 // wait
   Delay=0 Img=2 // splash instead of null
   Delay=300 ScaleX=75 Mp3=2 // splash grows
   Delay=0 Opacity=0 // splash disappears
   Rest

- - - - - КОНЕЦ КОДА - - - - -

 

Let us say, we have a different task now. The null has puffed up but it has not burst yet. However, it will burst as soon as someone tap it.

In a game, character can send and get messages. For example, when the null is touched, the Touch_Self message appears.

To let characters get messages, Game Pilot uses the Slot[ ] command. The Slot command defines a state for a character when an certain message appears.

In Game Pilot, messages can appear when one touches a character, when a timer has tripped, or just when one character wants to tell something to another one.

Messages have names, for example: Time0_Name, Touch_Self, Touch_Name.

A message could be connected with a state number using the Slot[name]=N command. For example, Slot[Touch_Self]=3.

So the program for the null should consist of the following blocks:

1. The null is gradually puffing up.

2. The null is puffed up and is waiting until someone taps it (here we will need the slot). If someone taps the null – go to state 3.

3. The null bursts.

There are three blocks altogether. So we need to create three states for our program - each state for a block.

 

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

Scale = 50

1: Img=1
   Delay=2000 // wait
   Delay=100 ScaleX=55 Mp3=1// grow
   Delay=2000 // wait
   Delay=100 ScaleX=60 Mp3=1// grow
   Delay=2000 // wait
   Delay=100 ScaleX=65 Mp3=1// grow
   Delay=2000 // wait
   Delay=100 ScaleX=70 Mp3=1// grow
   State=2

2: Slot[Touch_Self]=3 // If null touched – go to state 3
   Rest

3: Delay=0 Img=2 // splash instead of null
   Delay=300 ScaleX=75 Mp3=2 // splash grows
   Delay=0 Opacity=0 // splash disappears
   Rest

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

 

In the state 1, the null is puffing up. Please note that there is no Rest command at the end of this state. Instead of the Rest command, there is command State=2. The State command directs to another state.

In the state 2 there is a command:

Slot[Touch_Self]=3

This is a slot. This command connects the touch message with the state 3. [Touch_Self] means "„"touch itself"“". Under "„"itself"“" we mean a character whose description contains the slot.

So Slot[Touch_Self]=3 means: if someone touched the character, go to state 3.

 

Task 1:

Start Game Pilot, select "Prepare demo project", then select the "6 Command Slot" project. Open the project.

The description of the null character contains the code we have just explained.

Try to tap the null at the time it is puffing up. Has it burst?

Now, tap the null if you see it has already puffed up. Would it burst?

Would the null burst if it has already puffed up but you didn't touch it?

You might want to puts slots into the head of the file, so every time the message appear, the appropriate state begins.

 

Task 2:

In your own project where you added the ball character last time, try to use the command Slot[Touch_Self]= for the following purpose:

The ball increases by 15% if you tap a certain character on the screen.

Let us say, we have the character elephant among our characters. If you touch the elephant, the ball increases by 15%.

You can create two states for the ball: 1 – the ball waits, 2 – the ball increases. The best way is to put the slot [Touch_...] into the head of the file. So you get something similar:

 

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

Scale = 50

Slot[Touch_elephant]=2 // If elephant touched – go to state 2

1: Img=1 // ball waits
   Rest

2: Delay=1000 dS=15 Mp3=1// ball grows
   Rest

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

 

Run the program and look how it works. Every time you tap another character (in our example, the elephant), the ball increases by 15%.

You can say about the ball character that it is subscribed to the touch message of the elephant. We can subscribe any other character of the project to this message. Let us say, we have 20 different balls in our project. As soon as you touched the elephant, some of the balls increase, some disappear and some began to move. This all happens because there is the following string in the heads of the .stt-files of these characters: Slot[Touch_elephant]=(here state number) and because the appropriate states contain commands that make the balls increase/disappear/move.

You can also unsubscribe a character from any message. For this purpose, use the command without parameter: Slot[Touch_elephant].

In the code above, there is a command: dS=15. This command increases of decreases the image by a certain percent. For example, dS=15 means "increase the image by 15%". And dS=-15 means "decrease the image by 15%". This command is a bit similar to the Scale command. But the Scale command does not increase or decrease, it rather sets the size of the image to a certain percentage.
 

- Download the archive with project files for this lesson -


Privacy Policy    Terms of Use     Copyright © Rais Garifullin