Contents | Overview | Examples | Editor | Forum |
---|
The element is used to modify the data model.
Example:
<assign location="Var1" expr="5"/>
Name | Required | Attribute Constraints | Type | Default Value | Valid Values | Description |
---|---|---|---|---|---|---|
location | true | path expression | none | Any valid location expression. | The location in the data model into which to insert the new value. See 5.9.2 Location Expressions for details. | |
expr | false | This attribute must not occur in an <assign> element that has children. | value expression | none | Any valid value expression An expression returning the value to be assigned. See 5.9.3 Legal Data Values and Value Expressions for details. |
The children of the <assign> element provide an in-line specification of the legal data value (see 5.9.3 Legal Data Values and Value Expressions) to be inserted into the data model at the specified location.
<scxml datamodel="lua" name="Scxml" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">
<datamodel>
<data expr="0" id="Var1"/>
</datamodel>
<state id="Shape1">
<onentry>
<log expr="Var1" label="Var1"/>
<assign expr="5" location="Var1"/>
<log expr="Var1" label="Var1"/>
<assign expr="Var1 + 10" location="Var1"/>
<log expr="Var1" label="Var1"/>
<assign expr="Var1 * 10" location="Var1"/>
<log expr="Var1" label="Var1"/>
</onentry>
<transition target="End"/>
</state>
<final id="End"/>
</scxml>
Output:
[Log] Var1: 0
[Log] Var1: 5
[Log] Var1: 15
[Log] Var1: 150
<scxml datamodel="lua" name="Scxml" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">
<datamodel>
<data expr="{ Name="default" }" id="VarTable"/>
</datamodel>
<state id="Shape1">
<onentry>
<log expr="VarTable.Name" label="VarTable.Name"/>
<assign location="VarTable.Name">"new name"</assign>
<log expr="VarTable.Name" label="VarTable.Name"/>
</onentry>
<transition target="End"/>
</state>
<final id="End"/>
</scxml>
Output:
[Log] VarTable.Name: "default"
[Log] VarTable.Name: "new name"
<scxml datamodel="ecmascript" name="ScxmlForeach" version="1.0" xmlns="http://www.w3.org/2005/07/scxml">
<datamodel>
<data expr="[ 0, 0, 0 ]" id="t_INPUTS"/>
</datamodel>
<parallel id="p">
<state id="state_3">
<state id="state_3_off">
<transition cond="_event.data==1" event="event.2" target="state_3_on"/>
</state>
<state id="state_3_on">
<transition cond="! (_event.data==1)" event="event.2" target="state_3_off"/>
</state>
</state>
<state id="state_2">
<state id="state_2_off">
<transition cond="_event.data==1" event="event.1" target="state_2_on"/>
</state>
<state id="state_2_on">
<transition cond="! (_event.data==1)" event="event.1" target="state_2_off"/>
</state>
</state>
<state id="state_1">
<state id="state_1_off">
<transition cond="_event.data==1" event="event.0" target="state_1_on"/>
</state>
<state id="state_1_on">
<transition cond="! (_event.data==1)" event="event.0" target="state_1_off"/>
</state>
</state>
<state id="inputs">
<state id="configuration">
<onentry>
<foreach array="t_INPUTS" index="varIndex" item="varItem">
<send eventexpr="'event.' + varIndex">
<content expr="varItem"/>
</send>
</foreach>
</onentry>
<transition event="change.inputs" target="configuration">
<assign expr="_event.data.x" location="t_INPUTS[0]"/>
<assign expr="_event.data.y" location="t_INPUTS[1]"/>
<assign expr="_event.data.z" location="t_INPUTS[2]"/>
</transition>
</state>
</state>
</parallel>
</scxml>
If the location expression of an assign does not denote a valid location in the datamodel the processor MUST place the error error.execution in the internal event queue.
If the location expression of an assign denotes a valid location in the datamodel and if the value specified by 'expr' is a legal value for the location specified, the processor MUST place the specified value at the specified location.
If the value specified (by 'expr' or children) is not a legal value for the location specified, the processor MUST place the error error.execution in the internal event queue.
TOP | Contents | Overview | Examples | Editor | Forum |
---|