🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

State Transition Systems - How do I actually incorporate this

Started by
0 comments, last by Xer0botXer0 2 years, 11 months ago

Hi guys,

So I've been reading on HFSM, GOAP, behaviour trees and what not, and so far I'm unable to implement any of it into a test project.

Does anyone have pseudo code for say a HFSM ?

I'd like to get into a discussion regarding it so that I can return when I've encountered new problems, my idea is to create a system that I can use across multiple projects and attach/detach modules, the modules part is just something in addition to what I've read and seems interesting, if you remove a module the code still runs.

Say I've an NPC with a variable state set to “IDLE” and the NPC is tasked by the player as in AOE or an RTS or Turn based game to chop wood, so the GoalState is to chop wood, preconditions to reach this goal would be (i think) {has player selected npc, has player right clicked target tree, is npc near tree, does npc have an axe} and these I understand are also “states” but in this context they're referred to as preconditions of the goal state which is to chop wood, and I believe these preconditions would be booleans that when they're all true the NPC will run some chop wood method ..

So already I've got a dozen questions, where do I keep these states stored ? do I just place them into a 2d array and number them also how does the goal_state know what the preconditions even are ?

it still feels like I need to code everything instead of some automation going on where the states automatically pick the relevant preconditions.

I say so because I imagine that I can have sort of like parent or primary or tier 1 states, and then each of those states have their own collection of child secondary or tier 2 states/conditions that needs to happen first, but with the wood chopping example I also imagine that I wouldn't need to check for enemy in range condition because it's somehow irrelevant to the goal state of chopping wood.. although it would still need to be added or checked ? now I add it's night time and the NPC needs to return home mid walking towards the tree..

Then there's does the state machine code run in it's own object or class with which methods? or should it run within each individual NPC instance and then there's a precondition from the woodchopping sequence that requires a player selecting the NPC, I feel like that interaction is somehow seperate from the NPCs actions entirely.

I use GML at the moment but yes pseudo code would work, my current understanding in implementing this is something like:

I'm not sure where to start to get all these things to fall into place.

This topic is closed to new replies.

Advertisement