Page 1 of 1

State Machine demo!

Posted: Thu Apr 22, 2021 9:05 pm
by milon
Hey all,

I've been playing with states and overlays (not sure if that's the right term). I finally hammered out a decent state machine with less-elegant overlays (mini-states that can be stacked up arbitrarily). It was mostly a learning process for me, and it qualifies as a creation, so I'm positing it here. Everything is CC0, so use it however you like.

It features Fail, Load, Menu, Play, and Quit states with some fun effects tossed in. Try to spot which bits are overlays! :)

Post your questions, tweaks, etc.

Enjoy!

Re: State Machine demo!

Posted: Fri Apr 23, 2021 1:21 pm
by Gunroar:Cannon()
Nice, this reminds me of the state machine I used in this project, though mine was more behavior based and also had stateless AI, and was less flexible(?). :)

Re: State Machine demo!

Posted: Thu Oct 21, 2021 12:25 pm
by togFox
I really need to get into the whole state machine thing. I think it is "next level" for my coding development. I've always been hesitant because it's not essential to use a state machine but, of course, there are many ways to do things and this might be better so I'll jump into it and learn it.

Re: State Machine demo!

Posted: Thu Oct 21, 2021 5:50 pm
by milon
Awesome! I felt like that too, originally. It's only made me a better (and more organized!) coder! :D

The simple way to look at it is we're just using some well-organized tables in a very specific way. The current state is the key value used to look up other values, and those happen to be functions particular to a given state. It's also a very elegant way to avoid massive IF..ESLEIF.. blocks.

Re: State Machine demo!

Posted: Thu Oct 21, 2021 10:41 pm
by Gunroar:Cannon()
Wait, which kind of state machine is this? The AI kind or the screen manager kind?

Re: State Machine demo!

Posted: Mon Oct 25, 2021 4:59 pm
by milon
Screen manager - sorry that was unclear!