| 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”

```xml
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 | |—|—|—|—|—|—|