direct.fsm.FourStateAI

from direct.fsm.FourStateAI import FourStateAI

Contains the FourStateAI class. See also FourState.

Inheritance diagram

Inheritance diagram of direct.fsm.FourStateAI

class FourStateAI(names, durations=[0, 1, None, 1, 1])[source]

Bases: object

Generic four state ClassicFSM base class.

This is a mix-in class that expects that your derived class is a DistributedObjectAI.

Inherit from FourStateFSM and pass in your states. Two of the states should be oposites of each other and the other two should be the transition states between the first two. E.g:

          +--------+
       -->| closed | --
      |   +--------+   |
      |                |
      |                v
+---------+       +---------+
| closing |<----->| opening |
+---------+       +---------+
      ^                |
      |                |
      |    +------+    |
       ----| open |<---
           +------+

There is a fifth off state, but that is an implementation detail (and that’s why it’s not called a five state ClassicFSM).

I found that this pattern repeated in several things I was working on, so this base class was created.

__init__(self, names, durations=[0, 1, None, 1, 1])[source]

Names is a list of state names. Some examples are:

['off', 'opening', 'open', 'closing', 'closed',]

['off', 'locking', 'locked', 'unlocking', 'unlocked',]

['off', 'deactivating', 'deactive', 'activating', 'activated',]

durations is a list of durations in seconds or None values. The list of duration values should be the same length as the list of state names and the lists correspond. For each state, after n seconds, the ClassicFSM will move to the next state. That does not happen for any duration values of None.

More Details

Here is a diagram showing the where the names from the list are used:

+---------+
| 0 (off) |----> (any other state and vice versa).
+---------+

           +--------+
        -->| 4 (on) |---
       |   +--------+   |
       |                |
       |                v
 +---------+       +---------+
 | 3 (off) |<----->| 1 (off) |
 +---------+       +---------+
       ^                |
       |                |
       |  +---------+   |
        --| 2 (off) |<--
          +---------+

Each states also has an associated on or off value. The only state that is ‘on’ is state 4. So, the transition states between off and on (states 1 and 3) are also considered off (and so is state 2 which is oposite of state 4 and therefore oposite of ‘on’).

changedOnState(self, isOn)[source]

Allow derived classes to overide this. The self.isOn value has toggled. Call getIsOn() to get the current state.

delete(self)[source]
distributeStateChange(self)[source]

This function is intentionaly simple so that derived classes may easily alter the network message.

enterState0(self)[source]
enterState1(self)[source]
enterState2(self)[source]
enterState3(self)[source]
enterState4(self)[source]
enterStateN(self, stateIndex, nextStateIndex)[source]
exitState0(self)[source]
exitState1(self)[source]
exitState2(self)[source]
exitState3(self)[source]
exitState4(self)[source]
exitStateN(self)[source]
getState(self)[source]
isOn(self)[source]
notify = <direct.directnotify.Notifier.Notifier object>
sendState(self)[source]
setIsOn(self, isOn)[source]
switchToNextStateTask(self, task)[source]