Skip to content

Self Registering Scripts

Grisgram edited this page Aug 15, 2025 · 2 revisions

Aside of the other quite powerful ways to hook a script to a broadcast, this one here might very well be your preferred way to run scripts: Let them self-register with the broker!

The #broker command

You may put a #broker command in your script (normally on top but that's no requirement) to hook this script to an event.

Note

Using this feature requires a running broker! Best approach for this is, to leave the SCRIPTOR_BROKER_AUTOSTART macro from the Scriptor_Configuration file at its default value of true, so you will always have a broker running.

#broker <typename>[.property:value] <broadcast>

To make a script self-register with the broker upon compile, just tell the compiler with this preprocessor command, how it shall register the script. Let's go through the details:

Part Example Description
#broker This is the self-registration command
<typename> Monster The sender of the broadcast. This can be a game object or a code class, Scriptor works with both and can analyze inheritance of both
[.property:value] .race:Orc Put together, this is a broadcast-filter for Monster.race == "Orc" and the script will be triggered for Orcs only
<broadcast> MonsterDied The title of a broadcast message to match. Wildcards are not allowed here, each script must be attached to a fully qualified broadcast title

So in the example above you have just created a script that will run whenever an Orc dies!

Clone this wiki locally