-
Notifications
You must be signed in to change notification settings - Fork 5
Coroutine Methods
Returns: Any type, a value that has been passed by YIELD...THEN
, RETURN...THEN
, or PAUSE...THEN
Name | Datatype | Purpose |
---|---|---|
None |
If no value has been returned from the coroutine then this method returns undefined
. The returned value is reset to undefined
after resuming execution after a YIELD...THEN
or PAUSE...THEN
command. if the coroutine reaches the end of its code, the return value is reset to undefined
; if you'd like a coroutine to return a specific value, use the RETURN
command (as is normal for other GML functions). If the coroutine is cancelled using the .Cancel()
method then the return value is also reset to undefined
.
Returns: An instance ID or a struct, the scope that the coroutine was created in
Name | Datatype | Purpose |
---|---|---|
None |
Returns: Boolean, whether the coroutine was paused using the PAUSE...THEN
command or the .Pause()
method
Name | Datatype | Purpose |
---|---|---|
None |
Returns: undefined
Name | Datatype | Purpose |
---|---|---|
[returnValue] |
any | Value to return via the .Get() function. If not specified, undefined will be used |
Pauses execution of the coroutine, allowing it to be resumed at some later point. Coroutines that are waiting for an async event via the ASYNC_AWAIT_*
commands will be paused after the ASYNC_AWAIT_*
code has completed, this is so that async events cannot be accidentally missed. If the coroutine is already paused or has already completed then this method does nothing.
This method cannot be called from within the coroutine; instead please use the PAUSE
command.
Please note that this method should not be used to pause a coroutine from within its own code. Instead, use the PAUSE...THEN
command.
Returns: undefined
Name | Datatype | Purpose |
---|---|---|
None |
Resumes execution of the coroutine after it has been paused. If the coroutine was not paused or has already completed then this method does nothing. .Resume()
resets the returned value for the coroutine to undefined
.
Returns: Boolean, whether the coroutine has completed
Name | Datatype | Purpose |
---|---|---|
None |
A coroutine is considered "complete" when any of the three following things happens:
- The coroutine runs out of code to execute, much like you'd expect with normal functions
- Upon reaching a
RETURN
command - When the coroutine is cancelled using the
.Cancel()
method (see below)
In any case, the CO_ON_COMPLETE
completion code is executed.
Returns: undefined
Name | Datatype | Purpose |
---|---|---|
None |
Immediately halts the coroutine, completing it; the CO_ON_COMPLETE
completion code will be executed accordingly. .Cancel()
resets the returned value for the coroutine to undefined
.
This method cannot be called from within the coroutine; instead please use the RETURN
command.
Returns: undefined
Name | Datatype | Purpose |
---|---|---|
None |
Immediately halts execution of the coroutine and restarts code execution from the beginning of the coroutine's code. This will also call CO_ON_COMPLETE
. .Restart()
sets the returned value for the coroutine to undefined
.
This method cannot be called from within the coroutine; instead please use the RESTART
command.
Please note that this method does not reset variables set in the coroutine.
Returns: undefined
Name | Datatype | Purpose |
---|---|---|
state |
boolean | Whether this coroutine should hold a weak reference to its creator (if that creator is a struct) |
Returns: undefined
Name | Datatype | Purpose |
---|---|---|
state |
boolean | Whether this coroutine should automatically cancel itself if its creator is destroyed or garbage collected |
If a coroutine is cancelled due to its creator being destroyed or garbage collected, the CO_ON_COMPLETE
code block will still be executed.
N.B. A deactivated instance counts as a non-existent instance.
@jujuadams 2021