openOMSI GitHub Discord

Docs / Making content / HTML textures

Reading the vehicle

1 min readEdit this pagedocs/HTMLTEXTURE.md

JavaScript
window.omsi.update = function (d) {
    d.num, d.str      // script variables that changed since the last call (everything on the first call)
    d.vehicle         // the normalised snapshot, the same object as omsi.vehicle
    d.vars            // every variable so far, the same object as omsi.vars
};
omsi.vehicle The normalised state of the bus, with the same names on every bus (see below). You can also read it from timers.
omsi.vars.num, omsi.vars.str The latest value of every variable in the bus's own variable list, keyed by lower-case name.
omsi.getVar(name) One variable, any letter case. Gives a number, else text, else undefined.
omsi.apiVersion 1

Why two ways? OMSI buses name their variables however the author likes (door_0, Fahrertuer_Rechts, elec_busbar_main ...). If your page wanted to know whether the engine runs, it would have to know every single bus. omsi.vehicle solves that: the game translates the variables into one fixed layout, using the same rules it uses itself.

Things a bus doesn't have show up as null (numbers) or false (switches), never as a missing property. So omsi.vehicle.engine.rpm never throws, even on a bus without an engine model.

Numbers are rounded (speed to 0.1, rpm to 1 and so on). That way a value that only wobbles in the last digit doesn't trigger a redraw every frame.

Things that are specific to one bus (a mod's own switch, a battery voltage) are not standardised by OMSI. Read those with omsi.getVar("their_variable_name").

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

↑↓ to move↵ to open