A Composite State is a State which has an internal structure consisting of a set of states, transitions and other components.
A Composite State is represented by the icon placed on the state:
A Composite State's Entry and Exit Action together with a list of internal transitions can also optionally be shown (State Options) as follows:
Only transitions which have an event defined for them are included. The transition list is shown within it's own compartment.
►Note that the length of all action code shown is capped to minimize the clutter of model diagrams.
While LSL provides a state machine-based approach to designing scripts, the states themselves are 'flat'; they have no internal structure. For scripts trying to capture complex behavior, basic LSL can suffer from 'state explosion' whereby an unreasonable number of states are required to represent the various states of a complex script. As this is unwieldly, users typically choose to represent complex behavior through a series of global variables and functions, which can make it difficult to see the intent of the design clearly.
One of the major features supported by MiceOnABeam is the ability to design a script as a tree of hierarchical states. Here, a state can serve as a high-level abstraction, with only the appropriate design details shown at every level of the model. As well, since the design is captured as a graphical model, the script's design is that much more clear.
Any state can then have an internal structure, consisting of a set of states (i.e., substates), transitions and other components. Any substate within a Composite State, can itself have an internal structure, and so on. A state which does not have an internal structure is called a Simple State.
When a Simple State at a leaf of the state tree has been transitioned to, it becomes the Active State at it's decomposition level. However it's containing Composite State is also considered active, and so on to the root of the tree, (i.e., the top-level state of the model which by default takes on the name of the script itself).
Any transition that needs to access the internal structure of a Composite State either to enter the state, or to leave the state, must do so via an Entry Point or Exit Point respectively on the border.
A Composite State has some special modeling features associated with it. These include:
The following is a simple (contrived) model for flying a helicopter, whereby it can move in only one dimension at a time. The model consists at the top-level of the two states EngineOff and EngineOn which transition back and forth by a touch event.
Top Level State
The EngineOn state is a Composite State and is decomposed into states Idling and FullThrottle, which transition back and forth via the PowerUp and PowerDown transitions. Note the TouchOff Exit Point which is a Group Transition that will apply to all states contained within EngineOn, including substates contained within the Composite State FullThrottle, and so on. TouchOn is an Entry Point which transitions to Default Entry which would take the script to the Idling state.
FullThrottle is decomposed into states LevelFlight, Ascending and Descending, and these all are subject to the internal Group Transition CollectiveControl which leads to a Choice Point that determines the vertical movement of the helicopter. Note that the PowerDown Exit Point applies to all substates contained within FullThrottle, while the PowerUp Entry Point transitions to the Default Entry which would take the script to the state LevelFlight.
Within the LevelFlight Composite State, we have two Group Transitions, CyclicControl and RudderControl which can move the helicopter forward/backwards, left/right, or to simply hover. These are each represented by their own Simple States. Both the Hover and init (Initial Transition) Entry Points transition to Default Entry, and hence to the Hover state.
- A Composite State is just a specialized version of a Simple State, and so has all it's same semantics and capabilities, including State Entry and State Exit actions.
- MiceOnABeam itself does not place a limit on how deep the state hierarchy may go. However there are typically practical limits due to compiler and memory constraints of your virtual world environment. As a result, you may need to limit the nesting of states to a maximum of two or three levels.
- All states by default have an internal structure consisting of an Initial Point which can be seen by opening up a State Editor on the state. However, an Initial Point alone does not make the state a Composite State.
In a more complex model consisting of several Composite States, it can be tedious to traverse the nested state hierarchy to get to the particular state of interest. The State Explorer feature addresses this by providing a tree-like view of the model's state hierarchy so that you can easily zero-in on the exact part of your model that you wish to examine.