-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Labels
Milestone
Description
HOW TO USE STATES
Declare a state by calling State.create() and assigning it
to your state.
Ex: attackState = State.create()
Call HandleEvent. Every state should define HandleEvent.
This is how you do it.
attackState = State.create()
attackState.HandleEvent = function(msg)
if(msg.name == "Hit")
DoSomethingAboutIt()
return 1
else if(msg.name == "Dance")
...
else
return 0Only handle the messages you really care about.
Return 1 if you handled a message, return 0 if you did not
NOTE: you can also define HandleEvent like this:
someGenericFunction(msg)
...
end
attackState.HandleEvent = someGenericFunctionYou can optionally add the functions Enter and Exit
These will be called when a state enters or exits
SETTING UP THE STATE MACHINE ---
First, create all the states that you will need (see above on how to do that)
State Machines are created in onStartup
-- Call self:UseStateMachine{}
-- Then assign the sates as such
self:AddState { stateName = "stateIdle" }
self:AddState { stateName = "stateAttack" }
self:AddSubState { stateName = "stateWin" } -- stateWin is now a substae of stateAttackWhen you are done adding states, call SetState and pass in the name of the first state you
want to start in.
self:SetState { stateName = "stateIdle" }What we know: RE
Todo.