Codename Logo Codename Logo

Scripting - Event Callbacks

APIWikiTools

This is about the callbacks HScript calls in scripts. For the creation of custom events, see Custom Events / Notetypes.

Callbacks are an integral part of scripts as they fire when specific things happen in the engine, such as frame updates, state creation, and others. All scripts leverage this in order for them to do their thing.

Key callbacks

These are present in nearly every state you're in.

NameWhen this is called
createState creation
postCreateAfter state variables are instantiated (are not null)
updateEvery frame (sprite updating)
drawEvery frame (render sprites to screen)
destroyState destruction (such as switching states)

CancellableEvent

Majority of the callbacks, especially in PlayState, inherit the CancellableEvent class, which means that the specific callback may be cancelled if you wish to change what the callback usually does.

For example, take the below callback that is called once the countdown is started.

function onStartCountdown(event) {

}

If you wish to stop the countdown from starting, you call event.cancel(), like so:

function onStartCountdown(event) {
    event.cancel(); // Stops the event from continuing.
}

If you have worked with PsychLua before, you might see this method familiar. That's because this is exactly the Codename equivalent of Function_Stop. Here's an equivalent of the above code in Lua:

function onStartCountdown()
    return Function_Stop
end

Next steps in learning the In-and-out's of HScript

Written by: clairedeluneee
Last updated: 2025-11-15