Return: Difference between revisions
Jump to navigation
Jump to search
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. |
Doom64hunter (talk | contribs) No edit summary |
||
(7 intermediate revisions by 4 users not shown) | |||
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. | ||
'''definequote''' 125 SPAWNED | However, a '''return''' propagates along a call chain of [[state]]s and terminates the execution of the innermost [[event]] or [[actor]] code. | ||
To only exit the current state instead of the whole chain, instead use the [[terminate]] command. | |||
Not to be confused with the [[RETURN]] gamevar and [[return (userdef)|return (userdef structure)]]. | |||
== Examples == | |||
When the following code snippet is run, only quote 125 ("SPAWNED HEAVYHBOMB") is displayed. | |||
'''definequote''' 125 SPAWNED HEAVYHBOMB | |||
'''definequote''' 126 RAN EVENT_EGS | '''definequote''' 126 RAN EVENT_EGS | ||
'''definequote''' 127 RAN TEST STATE | '''definequote''' 127 RAN TEST STATE | ||
Line 11: | Line 21: | ||
'''onevent''' [[EVENT_EGS]] | '''onevent''' [[EVENT_EGS]] | ||
ifactor | ifactor HEAVYHBOMB | ||
{ | { | ||
state teststate1 ''// after teststate1's return, return from EVENT_EGS!'' | state teststate1 ''// after teststate1's return, return from EVENT_EGS!'' | ||
Line 22: | Line 32: | ||
{ | { | ||
''// the concrete actor is irrelevant, only placeholder'' | ''// the concrete actor is irrelevant, only placeholder'' | ||
[[spawn]] | [[spawn]] HEAVYHBOMB ''// --> EVENT_EGS'' | ||
userquote 125 | userquote 125 | ||
} | } | ||
Line 28: | Line 38: | ||
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. | 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. | ||
[[Category:Event manipulation]] |
Latest revision as of 04:20, 7 January 2024
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 propagates along a call chain of states and terminates the execution of the innermost event or actor code.
To only exit the current state instead of the whole chain, instead use the terminate command.
Not to be confused with the RETURN gamevar and return (userdef structure).
Examples
When the following code snippet is run, only quote 125 ("SPAWNED HEAVYHBOMB") is displayed.
definequote 125 SPAWNED HEAVYHBOMB definequote 126 RAN EVENT_EGS definequote 127 RAN TEST STATE state teststate1 return userquote 127 ends onevent EVENT_EGS ifactor HEAVYHBOMB { 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 HEAVYHBOMB // --> 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.