@@ -41,7 +41,15 @@ SCRIPT(clockwork);
41
41
_stateMachine setVariable [QGVAR(tick), _tick + 1 ];
42
42
43
43
private _current = _list select _tick ;
44
- private _thisState = _current getVariable [QGVAR(state) + str _id , _stateMachine getVariable QGVAR(initialState)];
44
+ private _thisState = _current getVariable (QGVAR(state) + str _id );
45
+
46
+ if (isNil " _thisState" ) then {
47
+ // Item is new and gets set to the intial state, onStateEntered
48
+ // function of initial state gets executed as well.
49
+ _thisState = _stateMachine getVariable QGVAR(initialState);
50
+ _current setVariable [QGVAR(state) + str _id , _thisState ];
51
+ _current call (_stateMachine getVariable ONSTATEENTERED(_thisState ));
52
+ };
45
53
46
54
// onState functions can use:
47
55
// _stateMachine - the state machine
@@ -52,15 +60,24 @@ SCRIPT(clockwork);
52
60
private _thisOrigin = _thisState ;
53
61
{
54
62
_x params [" _thisTransition" , " _condition" , " _thisTarget" , " _onTransition" ];
55
- // Transition conditions and onTransition functions can use:
63
+ // Transition conditions, onTransition, onStateLeaving and
64
+ // onStateEntered functions can use:
56
65
// _stateMachine - the state machine
57
66
// _this - the current list item
58
67
// _thisTransition - the current transition we're in
59
68
// _thisOrigin - the state we're coming from
69
+ // _thisState - same as _thisOrigin
60
70
// _thisTarget - the state we're transitioning to
71
+ // Note: onTransition and onStateLeaving functions can change
72
+ // the transition target by overwriting the passed
73
+ // _thisTarget variable.
74
+ // Note: onStateEntered functions of initial states won't have
75
+ // some of these variables defined.
61
76
if (_current call _condition ) exitWith {
77
+ _current call (_stateMachine getVariable ONSTATELEAVING(_thisOrigin ));
62
78
_current call _onTransition ;
63
79
_current setVariable [QGVAR(state) + str _id , _thisTarget ];
80
+ _current call (_stateMachine getVariable ONSTATEENTERED(_thisTarget ));
64
81
};
65
82
} forEach (_stateMachine getVariable TRANSITIONS(_thisState ));
66
83
};
0 commit comments