Callbacks¶
Functions the host calls in your script. Define the ones you need, with exactly these declarations. See How plugins run for the time budget they run under.
Main¶
void Main()
Runs once, after the plugin has been compiled and its saved settings have been put into their variables. Build the UI and load saved data here.
Example
UI::Window@ window;
UI::Text@ timeText;
void Main()
{
// Saved data first, then the UI that shows it
seconds = parseFloat(Storage::Get("seconds", "0"));
@window = UI::CreateWindow();
@timeText = window.AddText(FormatTime(seconds), TimeSize);
OnSettingsChanged(); // apply the saved settings to the new widgets
}
Update¶
void Update(float dt)
Runs every frame. dt is the length of the last frame in seconds. Read what the player did, update what's shown,
count time.
Example
void Update(float dt)
{
// Count racing time, and show it only on a track
window.visible = Race::OnTrack();
if (Race::IsActive())
seconds += dt;
timeText.text = FormatTime(seconds);
}
OnSettingsChanged¶
void OnSettingsChanged()
Runs after the player changes one or more of your settings, before your next Update. The new values are already
in the setting variables.
Example
[Setting name="Time size" min=16 max=160]
float TimeSize = 56;
void OnSettingsChanged()
{
// Text sizes are only read when set, so apply the new one
timeText.size = TimeSize;
}
OnDisabled¶
void OnDisabled()
Runs once, just before the plugin's script is freed: when the player turns it off in the plugin manager, when it's removed, or when a plugin it depends on is turned off or removed. Requires host 0.12.0.
The host already takes away your windows, panels, footer buttons, cursor request, leaderboard notes and editor
additions. Use OnDisabled for what it can't know about: changes you made to the game itself, such as HUD layouts,
a cosmetic you equipped, or objects you changed through the console. This is your script's last call, so nothing you
leave for a later Update will happen. Console::Run commands still run, because the host runs them itself.
It isn't called when the plugin is stopped by an error or by going over its time budget, or when the game closes.
Example
void OnDisabled()
{
// Give the game its own timer back
Hud::ClearLayout("PlayerUI/TimeGroup");
}
Script language basics¶
Plugins are AngelScript. Besides the plugin API, scripts have:
string, with+joining text and numbers ("restarts " + count),splitandjoinarray<T>, for examplearray<int> ids = {1, 2, 3};withlength(),insertLast()andremoveAt()parseInt,parseFloat,formatIntandformatFloatfor converting between numbers and text