Documentation

State Action Types

States can have different action types, which include entry, during, exit, bind, and, on actions. The actions for states are assigned to an action type using label notation with this general format:

name/
entry:entry actions
during:during actions
exit:exit actions
bind:data_name, event_name
on event_name:on event_name actions
on message_name:on message_name actions

For example, different state action types appear in the following chart.

After you enter the name in the state label, enter a carriage return and specify the actions for the state. The order you use to enter action types in the label does not matter. If you do not specify the action type explicitly for a statement, the chart treats that statement as an entry action.

This table summarizes the different state action types.

State ActionAbbreviationDescription
entryenExecutes when the state becomes active
exitexExecutes when the state is active and a transition out of the state occurs
duringduExecutes when the state is active and a specific event occurs
bindnoneBinds an event or data object so that only that state and its children can broadcast the event or change the data value

on event_name

noneExecutes when the state is active and it receives a broadcast of event_name

on message_name

noneExecutes when a message message_name is available.

on after(n, event_name)

noneExecutes when the state is active and after it receives n broadcasts of event_name

on before(n, event_name)

noneExecutes when the state is active and before it receives n broadcasts of event_name

on at(n, event_name)

noneExecutes when the state is active and it receives exactly n broadcasts of event_name

on every(n, event_name)

noneExecutes when the state is active and upon receipt of every n broadcasts of event_name

For a full description of entry, exit, during, bind, and on actions, see the sections that follow. For more information about the after, before, at, and every temporal logic operators, see Control Chart Execution Using Temporal Logic.

In the preceding table, the temporal logic operators use the syntax of event-based temporal logic. For absolute-time temporal logic, the operators use a different syntax. For details, see Operators for Absolute-Time Temporal Logic.

Entry Actions

Entry actions are preceded by the prefix entry or en for short, followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,). If you enter the name and slash followed directly by actions, the actions are interpreted as entry action(s). This shorthand is useful if you are specifying entry actions only.

Entry actions for a state execute when the state is entered (becomes active). In the preceding example in State Action Types, the entry action id = x+y executes when the state A is entered by the default transition.

For a detailed description of the semantics of entering a state, see Steps for Entering a State and State Execution Example.

Exit Actions

Exit actions are preceded by the prefix exit or ex for short, followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,).

Exit actions for a state execute when the state is active and a transition out of the state occurs.

For a detailed description of the semantics of exiting a state, see Steps for Exiting an Active State and State Execution Example.

During Actions

During actions are preceded by the prefix during or du for short, followed by a required colon (:), followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,).

During actions for a state execute when the state is active and an event occurs and no valid transition to another state is available.

For a detailed description of the semantics of executing an active state, see Steps for Executing an Active State and State Execution Example.

Bind Actions

Bind actions are preceded by the prefix bind, followed by a required colon (:), followed by one or more events or data. Separate multiple data/events with a carriage return, semicolon (;), or a comma (,).

Bind actions bind the specified data and events to a state. Data bound to a state can be changed by the actions of that state or its children. Other states and their children are free to read the bound data, but they cannot change it. Events bound to a state can be broadcast only by that state or its children. Other states and their children are free to listen for the bound event, but they cannot send it.

Bind actions apply to a chart whether the binding state is active or not. In the preceding example in State Action Types, the bind action bind: id, time_out for state A binds the data id and the event time_out to state A. This binding prevents any other state (or its children) in the chart from changing id or broadcasting event time_out.

If another state includes actions that change data or broadcast events that bind to another state, a parsing error occurs. The following example shows a few of these error conditions:

State ActionReason for Parse Error
bind: id in state BOnly one state can change the data id, which binds to state A
entry: time_out in state COnly one state can broadcast the event time_out, which binds to state A

Binding a function-call event to a state also binds the function-call subsystem that it calls. In this case, the function-call subsystem is enabled when the binding state is entered and disabled when the binding state is exited. For more information about this behavior, see Control Function-Call Subsystems Using Bind Actions.

On Actions

On actions are preceded by the prefix on, followed by a unique event, event_name, or message, message_name, followed by one or more actions. Separate multiple actions with a carriage return, semicolon (;), or a comma (,). You can specify actions for more than one event or message by adding additional on lines for different events or messages. For example, if you want different events to trigger different actions, enter multiple on event_name action statements in the state's label, each specifying the action for a particular event or set of events:

on ev1: action1();
on ev2: action2();

On actions execute when the state is active and the event event_name or message message_name is received by the state. This action coincides with execution of during actions for the state.

For a detailed description of the semantics of executing an active state, see Steps for Executing an Active State.

Related Examples

Was this topic helpful?