Skip to content

MSFS2020 How to Create and Use User Defined Lvars

JaimeLeon2 edited this page Jul 11, 2021 · 20 revisions

USER DEFINED L VARIABLES

Wouldn't you like to create your own variables? The MF wasm allows the user to automatically create, read and write to L: type variables (“Lvars”) for his or her own use. These user Lvars are typically used for precondition evaluation in internal control of Mobiflight configurations. This technique is very similar to the use of user offsets in FSUIPC. Here is a brief explanation of the steps you need to follow:

  1. Create a script in events.user.txt that writes the desired values to your Lvar. It can be anything. As an example, let's use the following script to toggle a Boolean variable called (L:MY_COUNTER) from 0 to 1 and back to 0, every time the event is executed. Other examples of possible use cases are given futher below.

    MY_EVENT#(L:MY_COUNTER, Bool) ! (>L:MY_COUNTER, Bool)

  2. Add one line to your msfs2020_eventids_user.cip file with the name of your new event:

    MY_EVENT

  3. Create an input configuration. Your event will need to be triggered from a Mobiflight input configuration. It can be a button or an encoder depending on what you need to do. This example is more suited for a button, so select a button from your board configuration. Select MSFS2020 Events, Group: User and select your event name MY_EVENT as your “On Press” event.

  4. Create an output configuration to read your Lvar. Specify SimConnect (MSFS2020) and enter directly into the Variable field the name of your variable. No need to select anything in the Group or Preset fields.

    (L:MY_COUNTER, bool)

  5. Save all your work and restart MSFS or use the touch command to have your new script recognized by the WASM module.

  6. In Mobiflight, you may need to press Stop and Run in MF to refresh the variables being monitored by the wasm module.

  7. Test your setup. Pressing the button should now show the Flight Sim value of the output config alternating between 0 and 1. When first testing a new event, I have found it is necessary to restart Mobiflight.

  8. You can now use this value to drive preconditions for other input or output configurations in the same way FSUIPC user offsets were used in the past.

It is also possible to monitor the values of your Lvars from the simulator side, by looking at the Local Variables tab, in the Model Behaviors window. If you named your variables with a unique prefix like “MY_”, it is even easier to find them by entering “my_” in the search filter.

MORE CODE EXAMPLES OF POSSIBLE USE CASES

 Counter button 0 to 4 with wraparound

 `MY_TOGGLE_EVENT3#(L:MY_COUNTER3) ++ 5 % (>L:MY_COUNTER3)`

 Counter encoder 0 to 5 without wraparound (clockwise and counter clockwise event)

 `MY_COUNTER4_INC#(L:MY_COUNTER4) ++ 5 min (>L:MY_COUNTER4) `
 `MY_COUNTER4_DEC#(L:MY_COUNTER4) -- 0 max (>L:MY_COUNTER4)`

 Counter encoder 0 to 8 with wraparound (clockwise and counter clockwise event)

 `MY_COUNTER5_INC#(L:MY_COUNTER5) ++ 9 % (>L:MY_COUNTER5)`
 `MY_COUNTER5_DEC#(L:MY_COUNTER5) 0 > if{ (L:MY_COUNTER5) -- (>L:MY_COUNTER5) } els{ 8 (>L:MY_COUNTER5) }`

Installation

User Interface

Examples and tutorials

MSFS2020

X-Plane

Workshops

Community Boards & Devices

Additional Information

Firmware

Clone this wiki locally