Some precision around variables and events in MSFS 2020

Questions about deployment and use of Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
SimPassion
Posts: 5338
Joined: Thu Jul 27, 2017 12:22 am

Some precision around variables and events in MSFS 2020

#1 Post by SimPassion »

I grabbed and put here some important and interesting points to know, when working on LUA scripting, around variables and events handling for FS2020 ...

from here : https://discord.com/channels/8115593830 ... 9371733003

The Artful Dodger — 02/17/2023 3:33 PM
Hello, everybody: I have a quick question. I know that it's possible for AM to receive L: vars but is it also possible for AM to send H: events?

@The Artful Dodger
Hello, everybody: I have a quick question. I know that it's possible for AM to receive L: vars but is it also possible for AM to send H: events?

Crunchmeister/Otto Pilot — 02/19/2023 4:27 PM
Yes it is. fs2020_event("H:eventName"). It's how most stuff works. All the standard events are H or K and fired the same way. (edited)

Sling — 02/22/2023 10:47 AM
In AM you don’t have to use the default A: for vars and default K: for key events but you do need to include the L: or H: when using any var or event that is not one of those defaults..

Crunchmeister/Otto Pilot — 02/22/2023 11:18 PM
Indeed. K: and A: aren't required as they're the default type of event and variable. I do it anyway now as I feel it's good practice as it keeps consistency across the code.


In short, for now :

Variables usable in AM are ... A: L:

Events usable in AM are ... K: H:

https://docs.flightsimulator.com/html/A ... tation.htm

Code: Select all

Variable Prefix 	System Name 	Description 	Units
A	Simulation Variable 	Gets a specified SimVar from a simulation object. 	Yes
B	Input Events 	 	Gets the value of the specified input event (see Input Event Definitions for more information). 	No
C	Callback Variables 	This variable prefix is only used when dealing with GPS Variables. 	Yes
E	Environment Variable 	This is an environment variable. See the section on Environment Variables, below. 	Yes
F	Function Library 	This denotes a built in function from the function library. See the Function Library section below for more details. 	No
G	Gauge Variables 	Gets a variable that can be used to transfer unitless data between gauges. 	No
H	HTML Event 	 	An HTML event sent to the JavaScript. These are defined in cockpit panel Model Behaviors, and only go in one direction: from the panel to the JavaScript / HTML code. H: events are not required to be defined ahead of time (similar to L: vars) and can be named with any contiguous string of alphanumeric characters. Each cockpit panel in Microsoft Flight Simulator sends a number of cockpit specific H: events that have no analogous key event, such as pressing individual buttons on an FMS computer. These individual panel specific events can be received by JavaScript instruments. 	No
I	Instrument Variable 	Used for variables within components, where the variable scope is the component and it's children. 	No
K	Key Event ID 	 	This is a specific variable for a key Event ID for user input.

(>K:TOGGLE_ICS)

Note that some key events require one or more values to be sent, so please see the section SimVars And Keys for more information on this.
	No
L	Local Variable 	 	Retrieves and/or creates a user defined local variable. If the local variable has not been defined in any of the associated files then it will be created and set to 0 the very first time it is referenced (and will not persist between runs). You can, however, define a default value for local variables using the following files:

    using the [LocalVars.N] section of the FLT file you can define a non-persistent local variable
    using the [LocalVars] section of the Systems Config file you can create a persistent local variable

This variable can be read and set within the scope of the user aircraft, and can be read by AI Aircraft.

IMPORTANT! "L:" vars can only hold numeric data and nothing else, eg: no strings, no binary values, no structs, etc...
	No
M	Mouse Variable 	 	Gets the state of the mouse for use in mouse click handlers. Please see the Mouse Variables section below. 	No
O	Component Variable 	Used for variables within components, where the variable scope is the component itself. 	No
P	Program Variable 	Same as the Environment Variable E: 	Yes
R	Resource Variable 	This is used to retrieve a value from an external resource, which can either be a legacy Help ID or Tooltip ID, or something from a custom localization file. See Resource Variables for more details. 	 
X	Calculator Variable 	This variable is used exclusively when creating Mission Definitions and is for referencing parameters created in the <CalculatorParameterList> element within an RPN calculation (inside a <CalculatorFormula>). 	No
W	Wwise Event 	 	This is a Wwise Event ID and allows you to trigger a Wwise event based on logic driven by the XML. This makes it more flexible than the sounds defined in sound.cfg and the AnimSoundEvents, although more complex to use. 	No
Z	Custom SimVar 	 	These are user-defined variables which are stored in an object's sim. The variable name is not one that has been predefined in the Microsoft Flight Simulator engine code, so anyone can create one with the name they want, as long as it doesn't conflict with an existing SimVar. 	No
 

Post Reply