Return: Difference between revisions
Helixhorned (talk | contribs) Add "return" page based on "break" and clarify differences. Might need more exact definitions where control-flow flags are reset and where not. |
Helixhorned (talk | contribs) m wording |
||
| Line 1: | Line 1: | ||
A '''return''' command is similar to '''[[break]]''' in that it | A '''return''' command is similar to '''[[break]]''' in that it stops code after the '''return''' from executing and thus can be used to exit a state early. However, a '''return''' proparates along a call chain of [[state]]s, so that when the following code snippet is run, only quote 125 ("SPAWNED LIGHTEFFECT1") is displayed. | ||
'''definequote''' 125 SPAWNED LIGHTEFFECT1 | '''definequote''' 125 SPAWNED LIGHTEFFECT1 | ||
Revision as of 15:32, 10 May 2012
A return command is similar to break in that it stops code after the return from executing and thus can be used to exit a state early. However, a return proparates along a call chain of states, so that when the following code snippet is run, only quote 125 ("SPAWNED LIGHTEFFECT1") is displayed.
definequote 125 SPAWNED LIGHTEFFECT1
definequote 126 RAN EVENT_EGS
definequote 127 RAN TEST STATE
state teststate1
return
userquote 127
ends
onevent EVENT_EGS
ifactor LIGHTEFFECT1
{
state teststate1 // after teststate1's return, return from EVENT_EGS!
userquote 126
}
endevent
onevent EVENT_LOADACTOR
ifvare THISACTOR 0
{
// the concrete actor is irrelevant, only placeholder
spawn LIGHTEFFECT1 // --> EVENT_EGS
userquote 125
}
endevent
Replacing the return by a break in the above example would lead to quotes 126 and 125 being displayed (in that order) at run time.