Hopefully you've got the hang of keyframes now. In this section I'm going to show you how to customize your FSM and change
an object's state on the fly


First we'll create a basic true room and a block in for us to play with. We want it to be dynamic and we
need to setup it's collision tags like in the earlier examples but this time turn on Cont. Upd(continuous update.)
Name it Block2.

We're going to animate the block to move about in a circle. So we need keyframes for it to move up a few squares, one to
make it go right a few, one for it to move down to the floor again, and one for it to move back to it's original position.
Here is a diagram of the animation we need. Name the keys for your animation the same as used in the paranthesis in the
picture.

Example: You need your first keyframe to be named floor the second to be Up, the third to be Right etc.
Then make the animation for the keyframe of the box moving up a few squares. Follow the diagram and make the nessesary keyframes for each
point. When the box is back where it started you should have 4 keyframes & 4 animations.


With that out of the way we're going to make one switch to activate all the animations(but not at the same time.) You'll see
what I mean in a minute. Make a box to serve as the switch and place an actionButton trigger in front of it...
I added a player start point here as well.

Here is where the FSM comes in. This gets a little tricky so bare with me and I'll try and explain it as best I can. Goto
your switch in F5 mode(which you should name theSwitch for the sake of the example) and hit 4 to bring up it's FSM.
We need to add states to it so that it doesn't trigger the same animation for the block each time we push it. But first,
add the states by pushing add. Name then like in the picture below.

Now select your box and add the same states; only this time use the Custom Strings button and add them in there.
Once you've added them all close the window and goto Messages for your box. Notice how there are new tabs for us
to use? Click the FSM_Send(Pos1) tab. Setup this tab as follows below:

this->DO_Animate(floor_to_up); Should be pretty self explanitory by this point. It does the animation that moves your
box from its startpoint to its up point.

parent::theswitch->fsm_switch(pos2); Sends the switch change pos2 to theswitch. This changes the switch's
state so that it doesn't do the same animation each time(we will have to modify theSwitch's T_Activate messages but
lets finish all the states for our Box first.)

Now, select the FSM_Send(pos2) tab. This one should be setup the same with with 2 exceptions.
  1. this->do_animate(floor_to_up); (needs to be) this->do_animate(up_to_right);
  2. Parent::theswitch->fsm_switch(pos2); (needs to be) parent::theswitch->fsm_switch(pos3);
So basically we're stepping through the animations one at a time and updating the object theswitch each step.
See if you can't figure out the settings for the FSM_Send(pos3) tab and then click here for the answer. We
need to do the same settings for FSM_Send(pos4) as well but this time make the fsm_switch
point to pos1 so that the switch is looped & make the do_animate point to the last animation.

Lastly we'll need to edit theswitch's T_Activate handler so that it knows what to do with the messages we're sending it.
Goto theswitch's FSM and click the T_Activate tab. You'll notice in the box labeled State Specific you now
have options on which states to specify for.

For each of the states we need to send it's corrosponding message to Box2. We do this under the T_Activate tab so that
the message is sent only when the button is pushed. These messages are the trigger for the animations.
Setup each of the different 'state triggers' here by selecting the trigger and entering:
parent::box2->fsm_send(posx);(X being the same as the state trigger we're modifying.)
So trigger 2 would get this:

Get it? Do the same for 3 but set 4 to send pos1 so that the switch starts over with the block. We're now done. Add a start
point and check it out.

Summary:

If you're still unsure as to what-the-hell we did here I'll try to sum it up.
  1. We created our objects and got the basics setup.
    1. Made our true room, made our box, made our switch, added a trigger
    2. We made our Box dynamic and then setup keyframes & animations so that the message handling is obvious.
  2. We added our 'states' to both objects.
    1. The objects use these to determine which commands to communicate and whether they are to send or recieve.
    2. Our switch object uses FSM_Switchs to interpret the Messages sent to it.
    3. The box object uses FSM_Send and sends our custom states to the switch. This updates the switch on the box's position.
    4. When the switch is pressed it then tells the box object which animation to use by way of which state it sends the box.


Download the *.lvl file here

<-- Back to easier stuff