Docs / Plugins / Plugin API reference
Events and timers
Register event handlers, timers and watches. The events themselves are listed under Events.
omsi.after#
omsi.after(seconds, fn) → integer id
Runs fn once, seconds of game time later.
Parameters: seconds number; fn function.
Since 0.1.5.
omsi.after(5, function() omsi.message("Five seconds later") end)omsi.cancel#
omsi.cancel(id) → boolean
Stops a timer, a watch or a hotkey; true when there was one.
Parameters: id integer.
Since 0.1.5.
omsi.emit#
omsi.emit(event, [...]) → nil
Sends an event to this plugin's own handlers at once (handy between the modules of a bigger plugin); an error of a handler is this call's.
Parameters: event string; ... any, optional.
Since 0.1.5.
omsi.on("fare_changed", function(price) print(price) end)
omsi.emit("fare_changed", 2.8)omsi.every#
omsi.every(seconds, fn) → integer id
Runs fn every seconds of game time.
Parameters: seconds number; fn function.
Since 0.1.5.
local id = omsi.every(1, function() print(omsi.clock()) end)
-- later: omsi.cancel(id)omsi.off#
omsi.off(event, fn) → nil
Removes a handler added with on.
Parameters: event string; fn function.
Since 0.1.5.
omsi.on#
omsi.on(event, fn) → the function
Adds a handler of an event (see the events); several may hear one event, in the order they were added.
Parameters: event string; fn function.
Since 0.1.5.
omsi.on("stop_arrive", function(name, id, number, delay)
omsi.ui.toast(name .. ", " .. omsi.fmt.delay(delay))
end)omsi.time#
omsi.time() → number
Seconds of game time since the plugin started (stands still while paused).
Since 0.1.5.
omsi.watch#
omsi.watch(kind, name, [fn]) → integer id
Runs fn(new, old) whenever a value changes: watch(name, fn) a variable of the bus, watch(kind, name, fn) of kind "var", "str", "sys" or "info" (a key of info()).
Parameters: kind string; name string; fn function, optional.
Since 0.1.5.
omsi.watch("Velocity", function(new, old) print(old, "->", new) end)
omsi.watch("info", "next_stop", function(new) print("next:", new) end)Something wrong or missing? Fix it on GitHub or open an issue.