State Circuits

To get started, or get more familiar, you can download the Snippet Pack :).

State Circuits

Create State Control in TD by connecting 3 simple types of COMPs to one another!
 
With these Circuits you explicitly describe:
1. The states your system can be in;
2. How events are dealt with when in these states;
3. How the states flow from one to another. 

Trough this you significantly reduce the degrees of freedom of your program which creates a strong and stable backbone to build everything else up on.

These Circuits come to live in any container which has at least a State menu paramater. You can employ them in multiple places to control small parts of your system like a character controller, or/and as the backbone of your whole system. I kept the system as minimal and native to TouchDesigner as possible which makes it very flexible and easy to debug. You can also edit, read or change or add whatever you want to suit your needs.

The stateful container

Parameters:
  • State : Menu                   # This represents the current state of  the system.
    • The menu entries are based on the State COMPs within this container. These are collected by searching for all the children with the tag "State".
  • Last state (readonly) : Menu   # Represents the last state
  • State pulse (readonly) : Pulse # Pulses when the state changes

Methods:
  • State( pulse : Bool = False, lastState : Str = None )                                  # Get the current state, possibly as a pulse the first frame, and/or only when coming from a specific last state.
  • OnStateChangePulse( )                                                                  # Get a pulse when the state changes
  • IsState( *states : Str, pulse : Bool = False, lastState : Str = None )                 # Is any state specified true (multiple entries possible because of the * operator)
  • IsStateFromList( stateList : [Str], pulse : Bool = False, lastState : Bool = False )   # Is any state from this list true
  • StateListToIndex( stateList : [Str], defaultIndex : Int = 0 )                          # Give a list of states and return the index of the active one. Handy for aligning the indexes of a Switch to the indexes of a list of states defined for example in a table dat! When none of the states are active, the defaultIndex is used.
  • StatesListToIndex( statesList : [Str], defaultIndex : Int = 0, separator : Str = " " ) # Split the list entries on spaces (or another separator) to allow for multiple states per Switch index

State COMP

Paramaters:
  • Inputs : COMP                        # The names of the State and/or Condition COMPs this state should listen for.
  • Any input active (readonly) : Toggle # True if any of the Active paramaters of a input (including the ones connected trough the COMPInput connector) is True.
  • Active (readonly) : Toggle           # True if the stateful container's State paramater equals the name of this COMP.
  • Redraw reference lines : Pulse       # Resets the scripts inside so any references lines drawn incorrectly are removed (doesn't happen very often nowedays)
  • On color : RGB                       # The color this comp has when it is the active state
  • Off color : RGB                      # The color this comp has when it is not the active state

Condition COMP

Paramaters:
  • Inputs : COMP                        # The names of the State and/or Condition COMPs this state should listen for.
  • Enhancer : COMP                      # Possibly input the name of an enhancer COMP here to give this condition some predesigned functionality (like making it a timer or an input)
  • Progression : Float                  # When this is one, the condition is met. Any value lower then this represents the progression towards the meeting of the condition.
  • Sticky : Toggle                      # The progression will stick to 1 when this has been hit during any time of the program. The only way to go back to any fractional progression or 0 is if the input has been active and inactive again.
  • Anxious : Toggle                     # The progression will only move move when the input is active (it doesn't dare to go on it's own).
  • Condition met (readonly) : Toggle    # Is true when the progression is 1
  • Any input active (readonly) : Toggle # True if any of the Active paramaters of a input (including the ones connected trough the COMPInput connector) is True.
  • Active (readonly) : Toggle           # True when the condition is met, and any input is active
  • Redraw lines : Pulse                 # Resets the scripts inside so any references lines drawn incorrectly are removed (doesn't happen very often nowedays)

Downloads: 194

Created at: 4.6.2023

Uploaded: 4.6.2023
First version! The core and essence of the system; and as far as I could test: bug free!
Download