Docs / Reference / Content formats
Scripts (.osc)
Scripts are the reverse-Polish programs that drive vehicles and objects. They live in a
vehicle's script\ folder, listed by the [script] file with their varlists and constfiles.
{frame}
(L.L.door_0) 0.9 >
{if}
1 (S.L.PAX_Entry0_Open)
{else}
0 (S.L.PAX_Entry0_Open)
{endif}
{end}Stack and operators#
- An 8-float working stack and a 10-float register file (
l0..l9load,s0..s9store without popping). - A value pushes onto
st[0]; everything shifts down andst[7]is dropped. - Binary operators pop both operands and push the result. Popping refills
st[7]with 0, so an underflow reads zeros. (a b -meansa - b.) - Binary:
+ - * / % = < > <= >= && || min max. Division and%by zero give 0. - Unary (replace
st[0]):sin arcsin arctan exp sqrt sqr sgn abs trunc ! /-/(negate). dduplicates.pipushes π.randomreplacesst[0]by a whole number in[0, n)withn = |round(st[0])|.- Operator names are compared as spelled:
Minand$CutEndare not operators.
Variables#
Access is (X.Y.name):
| 1st letter | Meaning | 2nd letter | Meaning |
|---|---|---|---|
L |
Load a float | L |
Local (object) variable |
S |
Store st[0] |
S |
System variable (Timegap, GetTime, ...) |
C |
Constant from a constfile | M |
Map variable |
F |
Curve from a 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) |
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_yare the mouse movement this frame while a[mouseevent]mesh is held. Its<event>_dragtrigger runs every frame the button is down, with 0 when the hand is still.AutoClutchis 1 unless the options say[no_automaticClutch]. At 0, a gear put in without the clutch pedal is thrown out at once.
Strings#
"literal" (may contain spaces) pushes onto the string stack. String operators: $+ $= $d $* $< $> $<= $>= $length $msg $RemoveSpaces $cutBegin $cutEnd $SetLengthL $SetLengthR $SetLengthC $IntToStr $IntToStrEnh $StrToFloat.
| Operator | Behaviour |
|---|---|
$IntToStrEnh |
Format string: first character is the pad, the rest the width ("02", " 2") |
$length |
Pushes the length and leaves the string |
$StrToFloat |
-1 for text that is no number |
$SetLengthL n |
Keeps the left n characters, or pads on the right |
$SetLengthR n |
Keeps the right n characters, or pads on the left |
$SetLength* |
Leave n on the number stack (unlike $cutBegin/$cutEnd) |
$msg |
Shows the top string without popping it |
A $ word that is not a string operator compiles to nothing, silently (a lone $, $=>,
$SetLengthM in mods). Any other unknown word is an error.
Blocks and flow#
- Blocks:
{init},{frame},{frame_ai},{macro:name},{trigger:name}...{end}. - Only
{end}ends a block. A block without it runs on into the next block's code, across script files too (the Opel Manta'santrieb_frameintocalc_eng_M), through the words before the next file's first header, at the same macro depth. - Block words are case-sensitive:
{End}is not{end}. - A
(M.L.name)finds only a macro defined below it, in the script files taken in their listed order (Omsi.exe builds the word stream from its end). A macro defined above its call, or the macro itself, ismacroinvalid, and the call does nothing. {if}...{else}...{endif}testsst[0] != 0and does not pop it. The stock scripts depend on it ((L.L.bremse_feststell) {if} ! (S.L.bremse_feststell)).- A reached
{else}jumps to the next{endif}, even when a stray{endif}already closed its{if}(the Procity's dashboard script has one). - Comments start with
'.%stackdump%writes 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's
engine.oscredefinescp_batterietrennschalter_toggleof itscockpit.osc.
Constfiles and varlists#
[const]
max_speed
80
[newcurve]
torque
[pnt]
0
0
[pnt]
2000
1200[const] name value,[newcurve] namefollowed by[pnt] x ypoints (piece-wise linear, clamped at the ends).- Constants and curves keep the first definition of a name (case-insensitive), within a file and across constfiles in their listed order.
- Varlists and stringvarlists: one name per line.
- A
(F.L.name)whose curve no constfile defines is logged as an error and gives 0.
OMSI's error names: SC_ErrorInCommand_{varinvalid,macroinvalid,constantinvalid,functioninvalid},
SC_ErrorInConstfile, SC_pnt_before_newcurve.
Compatibility patches#
A few mod scripts cannot show what they were written for under these rules. openOMSI patches them before compiling, recognised by their text:
- LiAZ 5292 line matrix: the line number is written with
" 3" $IntToStrEnh, so line 5E shows as5Einstead of blank orE. - Aachen's ibox: route entry uses a string digit buffer, so typed
0then1shows01and a lone1shows1, without automatic leading zeros.
Something wrong or missing? Fix it on GitHub or open an issue.