Skip to main content
GameDev.net gamedev.net
🔒 Locked

Statemachine?

Started by nano511 Sep 3, 2011 at 10:27 PM 5 replies 1.9k views
Original Post
nano511
nano511
I remember reading somewhere about a vector statemachine. It was really flexible and its just what i need but i cant remember all the details of how to implement it lol. If anyone could explain it better or show me an article that would be great

[font=verdana, arial, helvetica, sans-serif]basically, you pop on a state to the vector when you want that state to run ( it always runs the last state in the vector ) and if you need states to get information from another state you just stack them on top. Like a STATE_GAME would need information from STATE_SETTINGS, so they would be stacked. but STATE_GAME doesnt need information from STATE_MENU so STATE_MENU is deleted when its not being used.[/font]
nano511
nano511
No one knows what im talking about?
fastcall22
fastcall22
A finite state machine? There are countless implementations of the finite state machine; it all depends on the needs of your design. What are you looking for?
Nanoha
Nanoha
Not really sure, my state machine (for game states) works like a stack, you can push/pop but you can also clear the entire stack and start a new. If your att he main menu you can go into options etc and pop back out but if you want to go to "new game" then you no longer need the main menu so I clear and push a new state.

I've yet to come across a situation where one state needs information about another but I was thinking and if I had a "loading" state where a level is loaded then that might be a candidate. I'd planned to just pass in a referance to the required information rather than the loading state accessing it. The whole tell, don't ask thing.

I just had a look, my game state machine uses a vector inside (stl). Its using that rather than a stack as sometimes I want a state to be updated/rendered beneath the current one, a stack only lets you access the top.
Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.
Monkan
Monkan
Do you mean Vector as in STL Vector Container?

I suppose its like a stack based state machine?

Google Stack based FSM or stack based state machine and you might get what you want.

x
"To know the road ahead, ask those coming back."
nano511
nano511

Not really sure, my state machine (for game states) works like a stack, you can push/pop but you can also clear the entire stack and start a new. If your att he main menu you can go into options etc and pop back out but if you want to go to "new game" then you no longer need the main menu so I clear and push a new state.

I've yet to come across a situation where one state needs information about another but I was thinking and if I had a "loading" state where a level is loaded then that might be a candidate. I'd planned to just pass in a referance to the required information rather than the loading state accessing it. The whole tell, don't ask thing.

I just had a look, my game state machine uses a vector inside (stl). Its using that rather than a stack as sometimes I want a state to be updated/rendered beneath the current one, a stack only lets you access the top.



If you go to options and change settings, then pop if off, wont the settings be lost?


And also thanks everyone for telling me what it was called

Nanoha
Nanoha

If you go to options and change settings, then pop if off, wont the settings be lost?


Depends how its implemented, I have a semi-global "options" object. Though it is only really used by my main game state so I guess it could live there and be passed around.
Interested in Fractals? Check out my App, Fractal Scout, free on the Google Play store.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.