Custom Simulation Variables

Hi,

I am working on a custom aircraft. Is there a way to create a “Custom Simulation Variable” in the aircraft’s config files so that this variable can be read and written to/from Simconnect? This variable can and should exist only if the user has this aircraft selected.

Or any light on the subject where to create this custom variable?

Many thanks.

Hello,
You can create local variables called L:vars, they will be readable/writeable throughout the session.

for example (L:MyVariable,number) or (L:MyBool,bool)

they are readable and writeable in XML and in JS , and should be possible through simconnect.

1 Like

Thanks Marwan,

based on the name “local variables” instead of custom variables I was able to find something I can use. Looks like I can use the Gauge API in the SDK to register local variables.

Is there any other way to create new local variables (LVARS)? Like in a .cfg or .XML file?

Hi ,
You can update and set local variables through an update loop or button clicks of a model.xml of any aircraft.

I will share some examples once i get to my PC.

1 Like

Hello,
So you will find below example of the 2 ways you can set a variable through the modelbehaviour xml file of an aircraft, for example my interior model behaviour file is called HA420_interior.xml , and inside it I can have the codes of the following examples.

Setting and reading variable in the update loop of the model:

<Behaviors>
    	<Component ID="Update">
    		<UseTemplate Name="ASOBO_GT_Update">
    			<FREQUENCY>30</FREQUENCY>
    			<UPDATE_CODE>
    //your code goes here for example:
    //=============================exampe 1=========================================
    20 (>L:MyVairable,number)  //sets the value of the variable (L:MyVairable,number)  to 20,
    //=============================exampe 2=========================================
    (L:MyVariable, number) 30 + (>L:MyVariable, number)   // adds 30 to the variable, value is now 50. notice the format is Reverse polish notation (RPN);
    //=============================exampe 3=========================================
    if (A:Fuel tank center quantity,gallons) (L:MyVariable, number) > if{ 1 (>L:MyBool,bool) }  els{ 0 (L:MyBool) }      // reads simulation variable fuel tank quantity , compares it (L:MyVariable,number) , if greater set (L:MyBool,bool) to true (value of 1) else will set to false (value of 0)

    			</UPDATE_CODE>
    		</UseTemplate>
    	</Component>

And this is an example of setting a local variable through cockpit interraction:

 <Behaviors>
    <Component ID="HA420_BATTERY_MASTER" Node="HA420_BATTERY_MASTER">
    	<UseTemplate Name="ASOBO_GT_Push_Button">
    			<NODE_ID>HA420_BATTERY_MASTER</NODE_ID>
    			<ANIM_NAME>HA420_BATTERY_MASTER</ANIM_NAME> 
    			<LEFT_SINGLE_CODE>
    						70 (&gt;L:BM Pushed,bool) // here on button press, the local variable (BM pushed,bool) will be set to 70, notice the use of " &gt;" this is interchangeable with ">" , both can be used.
    			</LEFT_SINGLE_CODE>
    			<TOOLTIPID>%((A:ELECTRICAL MASTER BATTERY, Bool))%{if}TT:COCKPIT.TOOLTIPS.MASTER_SWITCH_BAT_ON%{else}TT:COCKPIT.TOOLTIPS.MASTER_SWITCH_BAT_OFF%{end}</TOOLTIPID>
    			<WWISE_EVENT_1>battery_switch_on</WWISE_EVENT_1> 
    			<WWISE_EVENT_2>battery_switch_off</WWISE_EVENT_2>
    	
    	</UseTemplate>
    	
    	
    	
    </Component>

 </Behaviors>

by the way, there is no need to declare L:vars, once they are mentioned in a code they are created automatically , if no value is assigned to them they will have a default value of 0.

1 Like

Many thanks. That is perfect. This is what I have been looking for.

Really appreciate the example and help. :grinning:

Cheers
Fritz

1 Like

Glad I can help, feel free to ask any time.

1 Like

Are Lvars accessible through SimConnect ?

No they are not. You found something wrong on the internet.

Simconnect - NO
WASM - Yes

You can create a WASM module in Visual Studio and that gives you access to the LVARS.

Look at this code. It reads the LVARS in WASM and creates a custom event that you can then read in SimConnect. Haven’t tried it myself, but it is demonstrating a way of getting LVARS into SimConnect.

and

1 Like