Previous Blog Next Blog
Prev/Next Blog
by date

FSM in TGB is done!

FSM in TGB is done!
Name:Gustavo Boni
Date Posted:Jan 23, 2007
Rating:3.3 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Gustavo Boni

Blog post
In my last plan i talked about how i was trying to create a scriptable Finite State Machine in TGB. It was just some words about how i was trying to figure out a way to use that in the script-side. I was so excited that i forgot the rule #1: "No pics, no blog". Now, the FSM is done and i can show you something. ^^


PS: using Adventure Kit art asset

It's a very simple scene: at the top left is the warrior's house and at the bottom right is the bank. Basically the warrior has four states: Sleeping, Eating, Looking Treasure and Banking.
The state diagram for the warrior is the following: (The red square shows two states i didn't create yet.)



The initial state is sleeping, so when i start the game, the warrior go to your house to sleep and recover your atributes (health, fatigue and hungry level). The next state is "Eating", and when "hungry" become full, the FSM changes to the "Looking for Teasure" state. If the warrior found the treasure, the state is changed to "Banking", if the warrior "hungry" is very low, it return to the "Eating", the same with the "Fatigue" but it returns to the "Sleeping" state.

All the state logic is done like this:


function lookingforteasure::onExecuteState(%this, %var)
{
if($warrior.hungry <= 95)
{
warriorStateInfo.setText("I'm hungry, need to have lunch");
return $TRANSITION_LOOKINGFORTEASURE_EATING;
}
else
{
if($warrior.fatigue <= 90)
{
warriorStateInfo.setText("I'm tired, need to go sleep");
return $TRANSITION_LOOKINGFORTEASURE_SLEEPING;
}
else
{
if(getRandom(1,100) <= 20)
{
//Found Treasure!
return $TRANSITION_LOOKINGFORTEASURE_BANKING;
}
}
}

return $TRANSITION_DONT_CHANGE;
}


This is the reason I create the states in script. If you have suggestions, let me know, please. =)

It's all. Hope you liked it ^^

The next step is Messaging.

Thanks,
Gustavo Boni

Recent Blog Posts
List:01/23/07 - FSM in TGB is done!
01/17/07 - Finite State Machine in TGB for RPG Games

Submit ResourceSubmit your own resources!

Timothy Aste   (Jan 23, 2007 at 17:57 GMT)
Wow this is pretty cool :)

OneST8   (Jan 24, 2007 at 08:13 GMT)   Resource Rating: 4
Nice nice!

Very interesting stuff :)

Gustavo Boni   (Jan 24, 2007 at 12:46 GMT)   Resource Rating: 5
@Tim: Thanks! =)

@OneST8: Thanks too man! =)

Thomas Buscaglia   (Jan 24, 2007 at 16:26 GMT)
Cool stuff. This looks remotely similar to my TorqueScript FSM superclass, with some minor differences. Mine is fueld by TorqueScript hackery. All states for an FSM are on the FSM's namespace and the state's are hashed. The only optomization I have in mind is to hash all the FSM types in a global singleton so there's only one instance of each type, but it's not too shabby for as small as it is.

Maybe we could collaborate to find a best solution and then post a resource for the community. Email me if you're interested.

Gustavo Boni   (Jan 25, 2007 at 03:05 GMT)   Resource Rating: 5
@Thomas: i've just sent you an email.

James Ford   (Apr 25, 2007 at 03:43 GMT)
I noticed your using the Adventure Kit art asset.. doesnt it have goal driven ai built into it?
Well im about to download it, so we will see!

You must be a member and be logged in to either append comments or rate this resource.