Wrong FSM?

What is wrong about this FSM? It always remains in “Off” state.

from direct.fsm import FSM

class StateFSM(FSM.FSM):

    def __init__(self, name):
        FSM.FSM.__init__(self, name)

    def filterWait(self, datatype, args):
        print "filterWait"
        if datatype == "distance" and args >= 60:
            return "Wait"
            return None
    def filterPursue(self, datatype, args):
        if datatype == "distance" and args < 60:
            return "Pursue"
            return None

    def enterWait(self):
        print "enterWait"
    def exitWait(self):
        print "exitWait"
    def enterPursue(self):
        print "enterPursue"
    def exitPursue(self):
        print "exitPursue"

I call it with:

stateFSM = StateFSM("stateFSM")
stateFSM.request("distance", 70)

but it doesn’t react…

The FSM will call filterWait() if it is already in the Wait state. It will call filterPursue if it is already in the Pursue state.

Initially, the FSM is in the Off state. This is neither the Wait nor the Pursue state, so it calls neither of your filter functions. Perhaps you meant to define a filterOff() function, or maybe a defaultFilter() function (which is called when there is not an explicitly matching filter function).


Oh, thank you, David! I thought these filters are rules when to enter some state while they are rules when to exit the state.