Codeware callbacks
How we can use events for control flow
Unlike How to create a hook, a callback can be be registered through Codeware callback system.
Example
Let's go over it bit by bit:
OnLoad
This function is always executed, because our ExampleService
inherits from ScriptableService
.
It sets the instance variable
callbackSystem
, making sure that we don't have to get it each time we want to use it.It binds to the
Input/Key
callback, telling Codeware to run the functionOnKeyInput
each timeIt prints to log
OnKeyInput
This function will be executed every time the registered event (Input/Key
) is triggered.
Since we are checking our internal variable found
before running any logic, this will only become active once.
Unregistering callbacks
Once you're done with your logic, you can unregister your callback again.
As of v0.5.19 (Mar 31 2024), unregistering Input/Key
will crash the game (link to github issue). Unregistering other kinds of callback works, though.
Last updated
Was this helpful?