Modding:Game Loop and Tick

From Trailmakers Wiki
Jump to navigation Jump to search

You can add an update function like so.

function update()
  -- do things every update
end

This is usually added to your main.lua to have an update-loop for your mod.

Caution: As it needs to be declared in global scope, the function can be overwritten and will be invoked with the re-declaration. There are no validation checks if you have duplicate declarations of the update function.

You can use tm.os.GetModDeltaTime() to get the number of seconds since the last execution.

Mods update on the main thread. If the mod updates takes too long, the game will be frozen until the update is done.