openOMSI GitHub Discord
Writing plugins

Docs / Plugins / Writing plugins

Debugging

1 min readEdit this pagedocs/PLUGINS.md

  • Watch game.log (in ~/.openomsi/) while you work. Every omsi.log and print line and every error is there, tagged [lua <name>]. omsi.warn, omsi.error and omsi.debug write at other levels; debug lines show with RUST_LOG=debug.
  • Save to reload. The game reloads a changed plugin within a second and says "Lua plugin reloaded". The Development Tools' Live switch does the same for a project.
  • Check the status. ~/.openomsi/plugins-status.json and the launcher's Plugins page show whether each plugin loaded, failed (with the error) or was switched off.
  • Find variable names. The bus's .osc scripts list them, and so does omsi.vars(). The environment variable OMSI_WATCH_VARS=Velocity,throttle logs every change of those variables (see Environment variables).
  • Catch expected errors with pcall. A wrong argument is an error that names the function and the argument.
  • Test for features with omsi.game.has("weather.set") and omsi.ui.version when a plugin should run on older versions too.
  • Rule out plugins. Turn on Disable plugins in the launcher (or set OMSI_NO_PLUGINS=1) to check whether a problem comes from a plugin.

Keep plugins light:

  • Keep on_frame short. Use omsi.every, omsi.watch and events for everything that does not need every frame.
  • Read only what you need, such as omsi.bus.velocity() or omsi.info_value("delay"), instead of building whole tables every frame.
  • Use omsi.ui.update to change one element; setting the whole panel every frame costs more.

Something wrong or missing? Fix it on GitHub or open an issue.

↑↓ to move↵ to open