Docs / Plugins / Writing plugins
Debugging
- Watch
game.log(in~/.openomsi/) while you work. Everyomsi.logandprintline and every error is there, tagged[lua <name>].omsi.warn,omsi.errorandomsi.debugwrite at other levels; debug lines show withRUST_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.jsonand the launcher's Plugins page show whether each plugin loaded, failed (with the error) or was switched off. - Find variable names. The bus's
.oscscripts list them, and so doesomsi.vars(). The environment variableOMSI_WATCH_VARS=Velocity,throttlelogs 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")andomsi.ui.versionwhen 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_frameshort. Useomsi.every,omsi.watchand events for everything that does not need every frame. - Read only what you need, such as
omsi.bus.velocity()oromsi.info_value("delay"), instead of building whole tables every frame. - Use
omsi.ui.updateto change one element; setting the whole panel every frame costs more.
Something wrong or missing? Fix it on GitHub or open an issue.