To include a Level Script with your mod, simply create a LevelScript.fs file and include it in the same ZIP or folder as your GOB file.
Minimal script example:
//////////////////////////////////
// Level Script.
//////////////////////////////////
// Level Start!
void levelStart(string levelName)
{
// Prints out the levelName and sector count.
// This is just an example and should be replaced by your own code.
// **Important** Script state is persistant across levels, use this function
// to reset any necessary state on level load.
system.print("Start Level {}, Sector Count {}", levelName, level.sectorCount);
}
// This is called once per game update.
void levelUpdate(float dt)
{
// This is called once per **game** update, dt is the delta time in
// seconds since the last game update.
}
// You can write internal helper functions as well.
// Finally, you can write functions called by `ScriptCall` from INF.
// ScriptCall functions can have up to 4 parameters in addition to the final
// parameter which will always be the elevator or trigger ID that called it.
void InfScriptCallExample(int elevID)
{
// Given the elevator ID, get the elevator from `level`. IDs don't change
// during level execution, so elev will remain valid while in the same level.
Elevator elev = level.getElevator(elevID);
// It is possible for a scriptCall function to keep running using 'yield'
// Keep running while the elevator is active, for example.
float prevTime = game.getGameTime();
while (elev.master)
{
// Do stuff while the elevator is active (master is on).
// Use game.getGameTime() to get the current game time to stay synced.
// This is an example of computing a delta time.
float curTime = game.getGameTime();
float dt = curTime - prevTime;
prevTime = curTime;
// Return control to the system. A delay in seconds can be passed in
// to handle timing.
// The script will resume after the yield with the call stack and local
// variables preserved.
yield();
}
}