I want to implement this sort of a conditional transition in SCXML:
current_state = s01
if (Math.random() < 50) go to state s02
else go to state s03
Is this sort of conditional targets supported in SCXML ?
To put it into the SCXML language, is the equivalent of the following snippet possible ?
<transition event="event_1">
<if cond="import java.util.Random; Math.abs(new Random().nextInt(100)) gt 50">
<target="s02"/>
<else/>
<target="s03"/>
</if>
</transition>
Would appreciate any pointers to their doc. for this / alternative strategies to handle it.
Thanks.
Something like the following (untested) code will do what you want.
<scxml
datamodel="ecmascript"
xmlns="http://www.w3.org/2005/07/scxml"
version="1.0">
<state id="s01">
<transition event="event_1" target="s02" cond="Math.random() > .5"/>
<transition event="event_1" target="s03"/>
</state>
<state id="s02"/>
<state id="s03"/>
</scxml>