Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Finite State Machine : the basics — Gideros Forum

Finite State Machine : the basics

MellsMells Guru
edited July 2012 in General questions
Hi community,

I'm trying to implement a basic finite state machine in my app.
My question is about the logic behind this system.

What would be the logical way to do between :
local firefly = Firefly.new("firefly1")
local stateLightsOn = State.new("LIGHTS_ON")
firefly:setState(stateLightsOn)
 
-- then Choice 1
firefly:onEnterState(stateLightsOn)
 
-- or Choice 2
stateLightsOn:onEnter(firefly)
twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps

Comments

  • atilimatilim Maintainer
    I would choose
    firefly:setState(stateLightsOn)
    Also your states can be simply strings instead of objects:
    firefly:setState("LIGHTS_ON")
    (it's a matter of taste)
  • @atilim agree entirely it's very much a personal choice as to how you want your state machine to work. :) (And yeah strings are the way to go, or at least they have been for me heh)
    ThumbHurt Games / FB: ThumbHurt Games / FB: Eli/Teranth | Skype: teranth37
  • @Mels, have you tried any of the FSM implementations suggested on the Lua wiki. I came across this one that looks interesting:

    http://lua-users.org/wiki/FiniteStateMachine

    Actually, there is a modified version of the same thing on GitHub that might be better:

    https://github.com/cornelisse/LuaFSM

    As it mentions in the text, the beauty of this scheme (courtesy of Lua's table mechanism) is that the states and events can be of any type, including tables and functions if required.

    Best regards

    Likes: atilim

    +1 -1 (+1 / -0 )Share on Facebook
  • @bowerandy great share, I couldn't remember where I had seen a LUA FSM example, you got it :)
    ThumbHurt Games / FB: ThumbHurt Games / FB: Eli/Teranth | Skype: teranth37
  • Thank you very much, very helpful.
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
Sign In or Register to comment.