-
-
Notifications
You must be signed in to change notification settings - Fork 108
MSFS2020 User Defined WASM Module Events Best Practices
Prepared by Jaime Leon - 8-Jun-21 _Updated by Jaime Leon - 14-May-24
Version 0.30
I have decided to update and rewrite this document in view that three years have passed and both MSFS2020 and Mobiflight have evolved.
-
Do learn RPN scripting. You will need to learn a little about this topic to understand the scripts used in MSFS. The scripting language used by MSFS is called RPN (“Reverse Polish Notation”). It is the way old HP engineering calculators worked, where numbers (or variables) are entered first and then the operand to be executed is entered last. The evaluation of RPN scripts is done using a stack operation analogy. For more information, see the RPN scripting guide in the MSFS SDK down below. Just to get a feel, the following example reads a variable value in feet and adds 100.
(A:PLANE ALTITUDE, feet) 100 +
*** EVENTS.TXT USE IS DEPRECATED *** All code can be input directly to the newer Input and Output code boxes in Mobiflight.
-
Variables and in-sim events (not wasm module events) names are enclosed in parenthesis. No space after the opening, nor space before the closing parenthesis. A variable will have a type (like A:, L:, H:, I:, M:, O:, etc), followed by the variable name, followed by an optional index (:1), followed by a comma, and followed by the optional units (percent, percent over 100, second, feet, mhz, khz, number, enum, bool, etc.). As an example:
(A:ENGINE ANTI ICE:1, Bool)
is an A type variable (or “Avar”, short for Airplane variable), whose name is ENGINE ANTI ICE, it is being accessed with an index of 1, and the variable is a Boolean (only takes 0 and 1 values). The space after the comma is optional.
-
Do note that event and script names are not case sensitive. The event names may contain any combination of letters and numbers, including spaces and underscores. The letters in the name are not case sensitive, but the variable types are required to be in upper case. So, for example:
0 (>L:MYVARIABLE_NAME)
is the same name and code as the following:
0 (>L:myVaRiaBle_Name)
Note the upper case “L” in the variable type is required. The rest is not case sensitive. Although not strictly necessary, we follow the case use (upper or lower) in the same way a variable is presented in MSFS. For example:
(L:XMLVAR_Pitot_1, bool)
will normally be shown the same way in our documented scripts. Also, the units are not case sensitive: bool, Bool, and BOOL are all equivalent.
-
Do note the meaning of the > sign after the opening parenthesis. This means to write a value to this variable or in the case of events, execute this event. Be careful when transcribing code, as it is very easy to miss entering the > and later it is very hard to spot the error. Examples follow:
(L:my_var) ++ (>L:my_var)
read my_var, increase value by 1, store in same variable1 (>L:ASCRJ_FCP_APPR)
set the variable to a value of 1(>K:AP_AIRSPEED_ON)
execute the autopilot air speed on event1000 (>K:AP_ALT_VAR_INC)
use parameter 1000 to execute autopilot altitude increase -
Do use unique names. USE OF EVENTS.TXT IS DEPRECATED. The Hubhop events database has a unique GUID for each event, so event name labels are just as a reference and althought it is highly desirable to have unique names, it is not a technical requirement any more. To prevent unintended duplicate names, it is suggested to prefix all your events with the target airplane, for example
CJ4_AUTOPILOT_MASTER_ON
orTBM930_PULSE_SWITCH_ON
-
Do use names that can be understood by others. The computer doesn’t care, but we do. Using "A32NX_AP_MASTER_ON" is much better than "A32NX_B2355", although both are valid names. Use shorter names and abbreviations when reasonable, without becoming too cryptic. Don’t include unnecessary words in your names. Nobody likes very long event names. Assume other people will need to understand and use your event.
-
Do pay close attention to the spaces in the code. This is important. The code parser is very unforgiving. There is no space after the if and els clauses. There is no space after the opening and before the closing parenthesis in a variable name. There MUST be at least one space between two variables or between any other elements in a script.
-
New InputEvents tab in Model Behaviors. Since MSFS2020 version 1.18.13, a redesign of the Model Behaviors window was made. Among the new features, there is a tab called "InputEvents" that shows all the registered events for a particular airplane, with the code related to each event. When selecting one event in this page, there is an option to "Add to control panel" which opens a new box to the right with the event details. Variations of the same event are presented in tabs: Init, Value, Inc, Dec and Set. The code presented in these boxes can be selected with the mouse and copy/pasted to a code editor. This makes it far easier to extract, edit and test events. Many more functions are available from this tab, but are beyond the scope of this writing.
This search, testing and recording of simulator events is an ongoing effort of the Mobiflight community, so that other members can benefit from our previous accumulated experiences and be able to build panels or home cockpits for flight simulation more easily.
If you have questions or comments, be sure to join us in the Mobiflight forum and the Mobiflight Discord server, where you will be able to find help from more experienced members and the latest news about this excellent piece of software.
Boolean, bool A type of variable that represents one bit of information and therefore only takes values of 1 or 0. Also interpreted as True or False, or as ON or OFF. Extensively used to represent the state of switches, LEDs, or even entire systems. It is the building block of binary logic.
LVAR “Local Variables” created by the mod airplane designers, often used to provide support for functions not included in the simulator
RPN “Reverse Polish Notation” Scripting language used in MSFS to program events, characterized by its reverse order notation, where numbers are entered first and the operands last
WASM “WebAssembly” is a new type of code that can be run in modern web browsers — it is a low-level assembly-like language with a compact binary format that runs with near-native performance
MSFS SDK Documentation: https://docs.flightsimulator.com/html/index.htm#t=Introduction%2FIntroduction.htm&rhsearch=status&ux=search
RPN Scripting: https://docs.flightsimulator.com/html/Additional_Information/Reverse_Polish_Notation.htm
https://www.prepar3d.com/SDKv5/sdk/scripting/rpn_scripting.html
Hubhop online events and variables presets database: https://hubhop.mobiflight.com/#/
Mobiflight web page: https://www.mobiflight.com/en/index.html
Mobiflight Github: https://github.com/Mobiflight/MobiFlight-Connector
Mobiflight Discord server: https://discord.gg/99vHbK7
Youtube Video: https://www.youtube.com/watch?v=PKBjEl9E5A4
- MobiFlight Connector Installation
- Mobiflight Connector BETA version installation
- Modules
- MobiFlight Connector Files Structure
- MobiFlight Connector Uninstall
- Modules Reset to factory default
- Verifying the WASM module installation and locating the MSFS2020 community folder
- Verifying the WASM module installation and locating the MSFS2024 community folder
- Using a Winwing FCU with MobiFlight
- Using VKB controllers with MobiFlight
- Providing logs from MobiFlight
- MobiFlight Connector How does it work
- Mobiflight Connector Main Window
- Flash module with MobiFlight firmware
- Input and Output devices
- Joysticks
- Midi Boards
- Sim Variables (for Output)
- Input Actions
- Merging configuration files
- Disabling specific COM ports
- Examples Output LEDs
- Examples Input Switch
- Example 7 segment display
- Example Servo motor
- Controlling LEDs with an output shift register
- Adding lots of buttons with an input shift register
- Beginner's guide to input multiplexers
- Key Matrix with standard MobiFlight and Multiplexers
- Tutorial Easy Driver and x.27 or x.40 Stepper Motor
- Tutorial for Airbus VS display via 7-Segment LED Module
- Example Analog Input Potentiometer
- Baron G58 Tutorial Gear, Flaps, Mags, ELT Input Output Programming
- Using Mobiflight to control arduino-based 3rd party panels (RealSimGear GNS530)
- How to use a VNH2SP30 DC motor shield with MobiFlight
- Using 3D printer mainboards
- Playing sounds by sending keystrokes to AutoHotKey
- Using the selector knob on a Honeycomb Bravo
- Using an adjustable 12 position switch as a GA starter
- Brightness of LCD displays with I2C
- Using three-position switches
- Transponder with one Rotary
- Workflow for Creating Flight Simulation Panels ‐ Part 1
- MSFS2020 RPN Tips and Tricks
- MSFS2020 Using the Custom Input Code Box
- MSFS2020 Install WASM module and Event List
- MSFS2020 How to Create and Use User Defined Lvars
- MSFS2020 How to Create a Blinking LED configuration
- MSFS2020 User Defined WASM Module Events Best Practices
- MSFS2020 Developer Mode, Model Behavior dialog and Console window
- MSFS2020 PMDG 737‐700 List of Events that require use of FSUIPC7
- MSFS2020 PMDG 737‐700 Calibrate throttle idle and reverse thrust using interpolation (Valkyrie)
- MSFS2020 PMDG 737-700 Chrono unit functions implemented in Mobiflight
- Configuring PMDG 737 Parking Brake Lever Auto-Release with a Servo in Mobiflight
- Using encoder to drive a value back and forth within a given range
- Adding a custom board to MobiFlight
- User guide - Community Board and Custom Devices
- Developing your own custom devices/boards