Creating a WorldScript
WorldScripts are units you can place inside of a level that perform some logic. Creating your own world scripts is useful for executing certain scripts in a level.
The setup
This is what the ScriptLink (a default script) looks like:
namespace WorldScript { [WorldScript color="176 196 222" icon="system/icons.png;416;128;32;32"] class ScriptLink { SValue@ ServerExecute() { return null; } } }
This script essentially means: when triggered, do nothing. This is useful for the reason that this script will trigger other scripts that are targeted by this one, without performing any action. In other words, it links scripts together, hence its name.
We store the class in a "WorldScript" namespace, as to not clutter the global namespace too much and to avoid name ambiguities. The name of the class will be the name of the script, as it will be shown in the editor and in the editor view. Use of capital letters is encouraged since in compact script mode, the editor will display the abbreviations of script names instead of their icon. For example, "ScriptLink" will show as "SL".
To indicate that the class is indeed a world script, we add the [WorldScript ...]
header, along with a color and an icon. This way the editor will be able to find and display the script. The color is a simple format of r g b
, so in the ScriptLink example above, this would be: 176 196 222
Order of execution
Script execution can only be initiated by the server. This means that ServerExecute
will be called first on the server, and after that ClientExecute
is called on the clients.
If the ServerExecute
method is not defined, the script can not be triggered, and you also will not be able to target it in the editor.
Network synchronization
The return value of ServerExecute
can be passed down to ClientExecute
, if necessary. You can build an SValue
using SValueBuilder
.
Functions
void Initialize() void Update(int dt) SValue@ ServerExecute() void ClientExecute(SValue@) void OnEnabledChanged(bool enabled) void DebugDraw(vec2, SpriteBatch&) SValue@ Save() void Load(SValue@ save)