Skip to content

Configuration

Juju Adams edited this page Jul 31, 2022 · 5 revisions

__CoroutinesConfig() is a script that contains a handful of macros that can be used to customize the global behaviour of the Coroutines library. You should edit these macros if you'd like to change default behaviour of the library.

 

COROUTINES_CHECK_SYNTAX

Expected values: Boolean, true or false

Whether to perform runtime syntax checking on coroutines. This carries a performance penalty when starting coroutines, but not when executing them. Syntax checking is, furthermore, something of an experimental feature. It may throw false negatives so if you're finding that the syntax checker isn't being helpful:

  1. Make a bug report! The problem is likely fixable!
  2. Set this macro to false

Additionally, runtime syntax checking carries a small performance penalty when creating a coroutine. If you feel like you need a little more speed, and once you've tested your game fully, you may want to set this macro to false to reclaim a little CPU time.

 

COROUTINES_DELAY_REALTIME

Expected values: Boolean, true or false

Set this macro to true to measure DELAY command durations in milliseconds. If you need per-frame accuracy then set this this macro to false.

 

COROUTINES_DEFAULT_CANCEL_WHEN_ORPHANED

Expected values: Boolean, true or false

Controls the default cancellation behaviour for coroutines when their creator is destroyed or garbage collected. Whether or not a specific coroutines is cancelled when orphaned can also be controlled using the .CancelWhenOrphaned() method.

N.B. A deactivated instance counts as a non-existent instance.

 

COROUTINES_DEFAULT_CREATOR_WEAK_REFERENCE

Expected values: Boolean, true or false

This macro is related to the one above. If you're creating a coroutine in the scope of a struct, the coroutine needs to keep a reference to that struct so that the .GetCreator() method can return a value. This causes a problem if you're expecting (or intending for) that struct to be garbage collected at some point because the coroutine will keep the struct alive if the coroutine holds a strong reference. Setting this macro to true will default every struct reference to a weak reference to avoid this problem. The type of reference that an individual coroutine holds can be further adjusted using the .WeakReference() method.

 

COROUTINES_GAMEMAKER_BROADCASTS_TRIGGER_NATIVE

Expected values: Boolean, true or false

Coroutines has its own native broadcast system. Broadcasts can be made with the CoroutineBroadcast() function and listeners can be set up with AWAIT_BROADCAST. GameMaker has its own broadcast system whereby sprites and sequences can emit events. GameMaker broadcasts can be picked up by Coroutines using AWAIT_ASYNC_BROADCAST, and the GameMaker global variable event_data will be accessible as you'd expect. Coroutine broadcasts and GameMaker broadcasts are two different systems and normally don't interact.

It is sometimes useful to be able to pick up GameMaker broadcasts using AWAIT_BROADCAST. Setting this macro to true will allow GameMaker broadcasts to trigger native Coroutine broadcast listeners. However, if a GameMaker broadcast triggers a native listener then event_data will not be accessible. Setting this macro to true will not disable AWAIT_ASYNC_BROADCAST so be careful not to confuse behaviours.