Yield

From Pico-8 Wiki
Jump to navigation Jump to search
yield( [...] )
Yields control back to the caller from within a coroutine.
...
Arguments to be passed to the coresume() that resumed its coroutine.

A coroutine is a special kind of function that can yield control back to the caller without completely exiting. The caller can then resume the coroutine as many times as needed until the function exits.

The coroutine calls yield() to suspend the coroutine and return control back to the caller in this way. As of PICO-8 v0.2.4b, it can accept a single option value to return from coresume() , although this is currently undocumented and may be dangerous to rely upon.

yield() returns all extra arguments passed to the coresume() that resumed its coroutine.

To terminate the coroutine, the function returns with the return statement. After this point, the coroutine is considered dead and cannot be resumed.

Examples

See cocreate() and coresume() for examples.

See also