by date
Finite State Machine in TGB for RPG Games
Finite State Machine in TGB for RPG Games
| Name: | Gustavo Boni | ![]() |
|---|---|---|
| Date Posted: | Jan 17, 2007 | |
| Rating: | 4.0 out of 5 | |
| Public: | YES | |
| Comments: | YES | |
| RSS Feed: | or Subscribe with . | |
| Profile Page: | View profile page for Gustavo Boni |
Blog post
Wow! This is my first blog! In the first place i want to thanks all the community for the help in the forums to learn Torque, really appreciate that.
So, let's talk about what i'm doing with Finite State Machines (FSM)^^
Months ago i created an FSM class implementation in c++ to see how it works following the excellent AI book Game Programming AI By Example. It worked nicely and i wondered how good it will be to have it working in TGB.
Thus, i thought in a prototype of a RPG game, where you would have a Warrior, an Monster and a Banker guy.
Each of them will have own states like: Eating, Sleeping, Fighting, etc. The FSM will handle all the actions making the Warrior go back to home to sleep if tired, for example.
The script code will be very simple. Basically you'll have to create a FSM to the player:
And then, create your states:
This is in the very beggining yet, i'll try to keep it as simple as i can.
Hope in the next blog show you some screens of this working too.
Thank you all for reading,
Gustavo Boni
So, let's talk about what i'm doing with Finite State Machines (FSM)^^
Months ago i created an FSM class implementation in c++ to see how it works following the excellent AI book Game Programming AI By Example. It worked nicely and i wondered how good it will be to have it working in TGB.
Thus, i thought in a prototype of a RPG game, where you would have a Warrior, an Monster and a Banker guy.
Each of them will have own states like: Eating, Sleeping, Fighting, etc. The FSM will handle all the actions making the Warrior go back to home to sleep if tired, for example.
The script code will be very simple. Basically you'll have to create a FSM to the player:
%myFSM = new FSM();
And then, create your states:
%sleeping = new State(sleeping);
This is in the very beggining yet, i'll try to keep it as simple as i can.
Hope in the next blog show you some screens of this working too.
Thank you all for reading,
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 your own resources!| Chip Lambert (Jan 17, 2007 at 15:24 GMT) |
| Matt Huston (Jan 17, 2007 at 15:30 GMT) |
| Phil Carlisle (Jan 17, 2007 at 15:41 GMT) |
i.e.
%myFSM = new FSM();
%myFSM.AddState("Resting");
%myFSM.AddState("Fighting");
You get the point. Its hard to keep the balance right when looking at torquescript vs C++, but I've found that the above interface works pretty well (i.e. the FSM is the scriptable object, everything else is managed by it).
| Gustavo Boni (Jan 17, 2007 at 15:55 GMT) Resource Rating: 5 |
@Phil Carlisle: yup, i got it Phil, but the reason to have the state in script is because eith the state object you can create the logic for this states. I mean, you will have 3 methods: onEntryState(), onExecuteState(), onExitState().
So, lets do it with the "sleeping" state.
function sleeping::onEntryState(%this, %var)
{
echo("I'm tired....");
}
function sleeping::onExecuteState(%this, %var)
{
if(tired)
{
return $TRANSITION_FIGHTING_SLEEPING;
}
}
function sleeping:onExitState(%this, %var)
{
echo("I have to wake up now... that sucks...");
}
| Oliver Rendelmann - DerR (Jan 17, 2007 at 16:44 GMT) |
| Michael Cozzolino (Jan 17, 2007 at 20:42 GMT) |
| Martin Schultz (Jan 17, 2007 at 21:01 GMT) |
| Phil Carlisle (Jan 17, 2007 at 22:12 GMT) |
So I could have
FSM.addState("onEnter","onUpdate","onExit","MyStateName");
It worked fine.. but I guess each to thier own.
| Gustavo Boni (Jan 18, 2007 at 00:09 GMT) Resource Rating: 5 |
| Tom Bentz (Jan 18, 2007 at 05:45 GMT) |
| Oliver Rendelmann - DerR (Jan 18, 2007 at 06:29 GMT) |
You must be a member and be logged in to either append comments or rate this resource.



4.0 out of 5


