Callbacks - coldrockgames/doc-scriptor GitHub Wiki

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

How Arguments Are Handled In Callbacks

You receive arguments in your callback script in the same way, they have been handled in earlier versions of GameMaker.

When the callback script gets invoked, it has these variables available:

  • argument_count contains the number of supplied arguments
  • argument0...argumentN are the arguments in the order they have been passed in
  • arguments[] is an array where you can access the arguments in a loop

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)
exit

array_sorter:
exit argument1 - argument0

For each entry in myarray the jump label array_sorter will run and it returns the sorting result through the exit 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.