-
Notifications
You must be signed in to change notification settings - Fork 0
Callbacks
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.
@scriptname or @jumplabel
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.
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.
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 - argument0For 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.
Back to Repo ● Wiki Home
Copyright © coldrock.games
- Home
- Scriptor Contents
- Scriptor Configuration
- Notepad⁺⁺ Integration
- Create a Script
- $ Variables
- Call a GML Function
- Scriptor global functions
- #-Commands
- The Scriptor Broker
- Broker Events
- Self-Registering Scripts
- Registering Broker Events
- Scriptor Broker File Format
- Extending Scriptor
- var
- new
- goto
- gosub and return
- return (without gosub)
- call
- reset
- Loops
- Conditionals