openOMSI GitHub Discord

Docs / Reference / Content formats

Scripts (.osc) - unit mc_exprcalc

4 min readEdit this pagedocs/FORMATS.md

An 8-float working stack (st[0..8]) and a 10-float register file (l0..l9 load, s0..s9 store without popping; the exe's TCache is array[0..9] of Single). Values push: the new value goes to st[0], everything shifts down one slot, st[7] is dropped.

Binary operators pop both operands and push the result; popping shifts the stack up and refills st[7] with 0, so underflow reads zeros. (The old Info_scriptcode.txt table suggests operands stay on the stack, but stock scripts such as (L.L.a) 0.5 > (L.L.b) 0.5 < (L.L.c) 4 = ! || && only make sense as A && (B || C) with popping semantics.)

Binary ops: + - * / % = < > <= >= && || min max with a b - meaning a - b. Division (and %) by zero gives 0 (the exe's divide handler compares the divisor with 0.0 and stores 0; the LiAZ 5292 charges its battery by Timegap V_generator / and relies on it).

Unary ops replace st[0]: sin arcsin arctan exp sqrt sqr sgn abs trunc ! /-/ (negate); d duplicates. pi pushes π, random replaces st[0] by a random whole number in [0, n) with n = |round(st[0])| (the exe calls Random(Abs(Round(x)))).

A reached {else} jumps to the next {endif} even when a stray {endif} has already closed its {if} (the Procity's dashboard script has one; ignoring that {else} blanked its odometer every frame).

$SetLengthL n keeps the left n characters or pads on the right, $SetLengthR n keeps the right n or pads on the left (read off the exe's str_SetLengthL/R); re-checked Sept 24 2026 in TXPC_calcblock_func op 0x25 at 0x5d584a: Copy(s, len-n+1, n)).

Unlike $cutBegin/$cutEnd, the three $SetLength* ops leave n on the number stack (the executor at 0x5d4a50 pops first only for the ops in its bit set at 0x5d5bac; the Kruger++ matrix display uses n again).

Mod scripts that cannot show what they were written for under these semantics are patched before compiling by omsi_script::compat (recognised by their text: the LiAZ 5292's 4-character line matrix pads the line to 4 $SetLengthL and then keeps 3 $SetLengthR, which left lines 1-9 blank and 5E as E; its number is now written " 3" $IntToStrEnh (padded with spaces, not zeros) → 5E. Aachen's ibox keeps route digits in float ibox_eingabe and blanks the display at 0, so leading zeros never appeared; mode-10 route entry uses a string digit buffer on ibox_Zahleingabe (empty until typed — no "00" / "02" $IntToStrEnh auto-pad): typed 0 then 1 shows 01, typed 1 alone shows 1; mode-7 line entry stays empty for free typing with no auto leading zeros).

{if} does not pop its condition (28 spots in the stock scripts work on it: (L.L.bremse_feststell) {if} ! (S.L.bremse_feststell) releases the parking brake, cond {if} (L.L.IBIS_busstop) 0 > && in the IBIS; the chura matrix writes x d -1 = ! {if} *).

Tokens found in the executable's operator table: /-/ <= >= && || sin arcsin arctan min max exp sqrt sqr sgn pi random abs trunc plus the single-character ones.

Variable access is (X.Y.name):

1st letter meaning 2nd letter meaning
L load float L local (object) variable
S store st[0] S system variable (Timegap, GetTime, …)
C constant from constfile M map variable
F curve from constfile: pushes curve(st[0]) $ string variable (L.$, S.$)
M macro call (M.L.name) or callback (M.V.name) V host callback
T sound trigger (T.L.name, T.F.name)

Strings: "literal" (may contain spaces) pushes on the string stack. String ops (from the exe): $+ $= $d $* $< $> $<= $>= $length $msg $RemoveSpaces $cutBegin $cutEnd $SetLengthL $SetLengthR $SetLengthC $IntToStr $IntToStrEnh $StrToFloat.

$IntToStrEnh takes a format string whose first character is the pad character and the rest the width ("02", " 2"). $length pushes the length and leaves the string (the chura matrix drops strings itself with (S.$.t) $length (S.L.n) 0 $* $+); $StrToFloat gives -1 for a text that is no number ("NORDSPITZE"), which scripts test for.

Blocks: {init}, {frame}, {frame_ai}, {macro:name}, {trigger:name} … {end}; control flow {if} … {else} … {endif} on st[0] != 0 (the condition is not popped). Comments start with '. %stackdump% dumps the stack to the log. Macro, trigger and variable names are case-insensitive.

A trigger or macro defined in two script files is the later file's: the O530 Citaro pack's engine.osc redefines cp_batterietrennschalter_toggle of its cockpit.osc (the ignition key turns one notch per press of E: key in, electrics, ignition, starter while held - the bus could not start otherwise), its ALMEX redefines IBIS_Zahlentasten.

Operator names are compared as spelled (Min, $CutEnd are not operators). A $ word that is not one of the string operators compiles to nothing, silently (a lone $, $=>, $++, $SetLengthM in mods); another unknown word is an error.

Constfiles: [const] name value, [newcurve] name followed by [pnt] x y (piece-wise linear, clamped). Constants and curves each keep the first definition of a name (ASCII case-insensitive), both within a constfile and across constfiles in their listed order. Varlists / stringvarlists: one name per line.

A (F.L.name) whose curve no constfile defines is logged as SC_ErrorInCommand_functioninvalid and still takes its argument, giving 0 (the O530 Facelift's ZF-6AP-1300/1700 lack two converter curves that its zf-eco.osc uses in the line that computes M_Wheel).

Errors in the exe: SC_ErrorInCommand_{varinvalid,macroinvalid,constantinvalid,functioninvalid}, SC_ErrorInConstfile, SC_pnt_before_newcurve.

System variables (varlist_system.txt): Timegap GetTime NoSound Pause Time Day Month Year DayOfYear mouse_x mouse_y PrecipType PrecipRate coll_pos_x/y/z coll_energy Weather_Temperature Weather_AbsHum wearlifespan AutoClutch SunAlt.

mouse_x/mouse_y are the movement of the frame while a [mouseevent] mesh is held: its <event>_drag trigger runs every frame the button is down, with 0 when the hand keeps still.

The stock scripts depend on it - the EN92 cash desk takes its swing speed from (pos - lastpos) / Timegap in that trigger, the rollers of the SD202 likewise, and the door scripts set their push per trigger and clear it at the end of the frame.

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

↑↓ to move↵ to open