Codeware callbacks
How we can use events for control flow
Example
class ExampleService extends ScriptableService {
// instance variables
private let callbackSystem: wref<CallbackSystem>;
private let found: Bool = false;
// This function is always executed
private func OnLoad() {
this.callbackSystem = GameInstance.GetCallbackSystem();
this.callbackSystem.RegisterCallback(n"Input/Key", this, n"OnKeyInput", true);
LogChannel(n"DEBUG", s"ExampleService loaded");
}
// Will always listen, but only react once
private cb func OnKeyInput(event: ref<KeyInputEvent>) {
if this.found {
return;
}
LogChannel(n"DEBUG", s"You pressed your key, going dormant now: \(event.GetAction()) \(event.GetKey())");
this.found = true;
}
}OnLoad
OnKeyInput
Unregistering callbacks
Last updated
Was this helpful?