Skip to content

Callbacks

Grisgram edited this page Oct 9, 2025 · 8 revisions

Callbacks are maybe the most powerful feature of Scriptor.

raptor makes heavy use of callbacks in its StateMachine, the Animation class, on FileAccess, Network traffic and many more. GML uses callbacks for functions like array_foreach and even other third party libraries like Scribble need a callback now and then.

Syntax

@scriptname or @jumplabel

Arguments In Callbacks - The $args Variable

You receive arguments in your callback script in the same way as when you supply arguments to your script when executing it: You have access to the $args variable.

Use Another Script As Callback

You may set any loaded script as callback for a function, even from subfolders of your scripts/ directory, like this:

array_sort(myarray, @helpers/array_sorter)

For each entry in myarray the script helpers/array_sorter will run.

Use A JumpLabel As Callback

There's an even more sophisticated way to use callbacks, where you don't have to declare an exclusive script file to run.

You may set any local jump label in the current script as a callback destination.

array_sort(myarray, @array_sorter)
return

:array_sorter
return argument1 - argument0

For each entry in myarray the jump label array_sorter will run and it returns the sorting result through the return command.
This is more elegant and has better performance than instantiating a full script as a callback.

Note

There is a priority in the resolution of a callback target:
First, the local script is examined, whether a jump label with the name exists. If there is one, it will be taken as target.
Only if there is no jump label with that name, Scriptor searches the loaded scripts for a script with that name.
If it is found, it will become the callback target. If neither a jump label nor a script is found with that name, the script stops with an exception.

Clone this wiki locally