chapitre précédent

Chapter 4 : Creation of state machines.

chapitre suivant


The state machines are pre-programmed functions; They allow you to scenarize your quest .
Let's see how to use some of these state machines in your quest .

1: Create a simple state machine.
Right click in the edition windows then select "Add machine".
Choose the state machine you need (when selected, read description on top left to know its purpose).

Example 1.
Select the state machine "container1"
Fill the properties window of the state machine with the following parameters.
Show

Enter new key: give1
3D object: initial close. The 3D object before you used it.
ex:
CHARRUE
3D object: final open. The 3D object after you have used it.
ex:
CHARRUE
Received object: The object to give to the player.
ex:
object1 (object "devastator" created previously. See the quest objects in chapter3)
Sound to play when objet is given: The sound to play when the object is given .
ex:
ITEM_DROP

Move the frame "give1_0" inside the roomzone "maison1".
Pass in 3D edition of "maison1" place the plow and put the collisions around.
Show
In the game if you click on the plow, you obtain the object1 "Dévastator".

Example 2.
Select the state machine :
containerAttack2
Fill the properties window of this state machine with the following parameters.
Show

Enter new key : needdevastator
Sound to play when object is given:
CAISSEOPEN
Received object B: The object to be given to the player.
ex:
ITEM_CRYSTAL3
Object A to wear: The weapon that the player must equip himself with.
ex:
objet1
3D object: final open: The 3D object after we have used it.
ex:
CAISSE_O
3D object: initial close: The 3D object before we use it.
ex:
CAISSE_C

Move the frame "needdevastator_0" inside the roomzone "maison1".
Pass in 3D edition of "maison1" and place the case
Show
In the game if you break the chest when you are holding the object "Dévastator" you receive a cristal.

Example 3.
Select the state machine :
containerMonster1
Fill the properties window of this state machine with the following parameters
Show

Enter new key : oeuf1
3D object: initial close. The 3D object before we used it.
ex :
2OEUFB
3D object: final open. The 3D object after we have used it.
ex :
2OEUFD
Monster to generate: Monster that be generated when we click on this state machine .
ex :
MYSTVYVERN4
Sound to play when monster appears:
BARRELOPEN

To add some similar state machines , use the function "instance"(very useful for the doors for example)
-Right click on the frame of the egg and select "Instances" then "Add".
-Make this operation two times and move the frames "oeuf1_0","oeuf1_1" and "oeuf1_2" inside the roomzone "entrée1".
Show
-Pass in 3D view edition of "entree1" and place the eggs in the appropriate areas.
Show
Now in the game if you click on one of the eggs , it breaks it and a vyvern appears .

Example 4.
Select the state machine :
pnj1
Fill the properties window of the state machine with the following parameters.
Show

Enter new key : rat1
Name of the character:
Rat d'égouts.
Text diplayed when we speak to him :
sscchh ... miamm ... scchh ... miammm.
Object to start transformation :
pizza
Transforms into this monster :
RATMAN
Text displays when he transforms :
gloups
Name of the model :
rat

-Move the frame "rat1_0" inside the roomzone "custom1".
-Pass to 3D view edition of "custom1" and place the rat in the center of the room
Show
In the game if you give a piece of pizza to the rat, he transforms into a rat man.

The others state machines work almost the same , so let's take a look at some particular cases.

2: Create a state machine with messages.
Select the state machine
LeverMessage1
Fill the properties window of the state machine with the following parameters
Show

Enter new key : magicbox
3D object: Lift up, close.
ex :
CHEST_C
3D object: Lower, open.
ex :
CHEST_O
Message number to be sent when we open it :
ex :
1
Message number to be sent when we close it :
ex :
0
Message number to deactivate the lever :
ex :
2
Sound :
ex :
CLIC3

-Move the frame of "magicbox_1" inside the roomzone "custom1".
-Pass in 3D view edition of "custom1" and place the trunk.
-Select the state machine :
basicObject1
-Fill the properties window of the state machine with the following parameters
Show.

Enter new key : magicmessage
Delay before this state machine is ready to regenerate:
10
Object to generate :
pizza
Message number that deactivates this state machine :
2
Message number that generates the object :
1
3D object :

-Move the frame "magicmessage_1" inside the roomzone "custom1".
-Pass in 3D view edition of "custom1" and place the state machine.
The messages are activated only when the state machines are linked.
This is how to proceed :
-Pass in 3D view edition of "custom1"
-Click on "add link" icon , now, left click on the state machine that generates the message "magicbox_1" then click on the state machine that received the messages "magicmessage_1".
Show

In the game each time you open the trunk you obtain a piece of pizza.
Now we are going to add some state machines to complement this one.
Imagine that we want to deactivate the trunk "magicbox_0" with a lever.
Select the state machine :
LeverMessage1
Fill the properties window of the state machine with the following parameters
Show

Enter new key : levier1
3D object : Lift up, close.
lever_c
3D object: Lower, open.
lever_o
Message number to be sent when we open it :
2
Message number to be sent when we close it :
1
Message number to deactivate the lever :
3
Sound :
CLIC3

Make a link from "levier1_0" to "magicmessage_0".

We can add an explosion on the trunk to make it more dramatic .
Select the state machine :
effect1.
Fill the properties window of this state machine with the following parameters
Show

Enter new key: fx
3D object : Not visible.
Message number that displays effect:
2
Message number that deactivates this state machine:
1
Effect to play:
explode
Options:
No collision
Delay before this state machine is ready to display a new effect:
500

Place "fx_0" behind the coffer "magicbox_0" in the 3D view.
Make the link from "levier1_0" to "fx_0".
Show

Well, let's explain what we have done.
Each time the trunk "magicbox" is open , it sends the message 1 to "magicmessage" that generates a piece of pizza, the message 0 (when the trunk is closed) does nothing at all.
If we activate the lever , the message 2 is sent to "magicmessage"(it deactivates the trunk, so we don't have pizza any more) and to"fx_0" too (wich makes the trunk explode).
Now if we activate again the lever , the message 1 is sent to "fx_0" wich is deactivated (so it won't explose any more).

NOTE : Each state machine can send and receive 8 links maximum

3 : Create a state machine with variables.
This type of state machine works like an events counter.
In this example , the player must put 3 crystals on a specific flagstone.When the 3 cristals are on the good place , a trunk will open by itself and give a fourth crystal.

Select the state machine : ContactObj
Fill the properties window of this state machine with the following parameters
Show

Enter new key : contact1
3D object: switch released.
PLATE3_0
3D object: switch pushed.
PLATE3_0
Message number to be sent when pressed:
1
Message number to be sent when released:
0
Object to detect:
ITEM_CRISTAL1

Create 2 others similar state machines with each "ITEM_CRISTAL2" and "ITEM_CRISTAL3" for the parameter "Object to detect:".
Move the 3 frames of these state machines to the roomzone "room1".
Select the state machine :
addVar2
Fill the properties window of this state machine with the following parameters
Show

Enter new key : testcontact1
Message number used to disconnect this state machine:
7
Value to add:
1
Virtual object to use for variable:
virtuel1
Message number used for the variable:
1
3D object: Not visible.

Create 2 others similar state machines
Move the 3 frames of these state machines and the frame of "virtuel1" inside the roomzone of "room1".
Select the state machine :
testVar
Fill the properties window of this state machine with the following parameters
Show
Enter new key :
testv
3D object: not visible.
Message number that begins the test:
1
Virtual object to use for variable:
virtuel1
Value to compare: the value we want to obtain
ex: 3
Operator:
Equal
Message number to be sent if the test is OK:
6
Message number to be sent if the test fails:
0
Message number used to disconnect this state machine:
7

Move this state machine inside the roomzone "room1".
Select the state machine :
containerMsg1
Fill the properties window of this state machine with the following parameters
Show

Enter new key : gencristal
3D object: initial close.
CHEST_C
3D object: final open.
CHEST_O
Received object:
ITEM_CRISTAL4
Sound to play when object is given:
BOSXHIT
Message number that gives object:
6

Move the trunk to the roomzone "room1".
Select the state machine :
effect1
Fill the properties window of this state machine with the following parameters
Show

Enter new key : fxcoffre
Delay before this state machine is ready to display a new effect.
500
Options:
No collision
Effect to play:
ex :
detection
Message number that deactivates this state machine:
2
Message number that displays effect:
0
3D object: Not visible.

Move the frame of "fxcoffre_0" to the roomzone "room1".
Organize the frames of the new state machines in the hierarchy view
Show
Pass in 3D view edition of "room1" and move the states machines then makes the following links .
"contactx" to "testcontactx"
"testcontactx" to "testv"
"testv" to "gencristal"
"testv" to "fxcoffre"

You must obtain something like this:Show
Explanation:
When you put the right crystal on the right "contactx", it sends the message1 to "testcontactx",so the value +1 will be added to "testv".
"testv" tests the value of the variable until we obtain 3 ,then it sends the message 6 to the trunk "gencristal_0" to open it and give the cristal "ITEMCRISTAL_4".
If the total of "testv" is not 3, it sends the message 0 to "fxcoffre" that plays the effect "détection".

Most types of state machines have been studied.
The others won't cause you any problems, they are a declination of the state machines we have just seen.
This tutorial comes to its end , let see the final part : The generation of the quest

Chapter 5 : Generation of the Quest.