PICO-8 Wiki
(costatus now works in Pico-8 0.1.8)
Tags: Visual edit apiedit
(→‎See also: trace)
(4 intermediate revisions by 3 users not shown)
Line 6: Line 6:
 
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.
 
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 <code>costatus()</code> function takes a coroutine object and returns its status, either <code>'suspended'</code> or <code>'dead'</code>. You can use this to test whether the most recent call to [[Coresume|coresume()]] yielded or terminated.
+
The <code>costatus()</code> function takes a coroutine object and returns its status as a string value, either <code>'running' 'suspended'</code> or <code>'dead'</code>. You can use this to test whether the most recent call to [[Coresume|<code>coresume()</code>]] yielded or terminated.
  +
  +
== Technical notes ==
  +
  +
When a coroutine dies unexpectedly, this status merely goes to <code>'dead'</code>, but additional information is also available about the reason and the location. See [[Coresume|<code>coresume()</code>]] and [[Trace|<code>trace()</code>]] for details.
   
 
== Examples ==
 
== Examples ==
   
See [[Cocreate|cocreate()]] for an example.
+
See [[Cocreate|<code>cocreate()</code>]] for an example.
   
 
== See also ==
 
== See also ==
   
* [[Cocreate|cocreate]]
+
* [[Cocreate|<code>cocreate()</code>]]
* [[Coresume|coresume]]
+
* [[Coresume|<code>coresume()</code>]]
* [[Yield|yield]]
+
* [[Trace|<code>trace()</code>]]
  +
* [[Yield|<code>yield()</code>]]
 
[[Category:Reference]]
 
[[Category:Reference]]
 
[[Category:API]]
 
[[Category:API]]

Revision as of 23:02, 23 May 2020

costatus( cor )
Tests whether a coroutine is suspended (returns true) or dead (returns false).
cor
The coroutine to test.

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 costatus() function takes a coroutine object and returns its status as a string value, either 'running' 'suspended' or 'dead'. You can use this to test whether the most recent call to coresume() yielded or terminated.

Technical notes

When a coroutine dies unexpectedly, this status merely goes to 'dead', but additional information is also available about the reason and the location. See coresume() and trace() for details.

Examples

See cocreate() for an example.

See also