Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Building a Script To Create a Toggle

Featured Replies

I am attempting to create a toggle switch for a water injection feature on the Aeroplane heaven P-47. I suspect I will need to create a script. I searched other posts about scripting and found this:

  1. Make sure that AAO is connected to the sim and that you are sitting in the cockpit
  2. Open "Scripting->Script Editor"
  3. Copy and paste my code above into the big white box
  4. Use the "Test" button to see if it works
  5. Enter a "Title" for the script at the top and select a group, for example "Scripts". (you can create your own groups with the "Manage Script Groups" button.
  6. Press "Save as new"
  7. Open your button definition
  8. Delete the Key Up
  9. Open the Key Down selection, scroll down to the group that you've selected for the script, open the group, doubleclick on the title of your script

So the problem I have remaining is what kind of syntax/structure I need to include in my script.  I have never built a script before. The event I am using is

INSTRUMENT_SWITCH_Waterinjection_Set

Can someone offer a suggestion as to what my script for a toggle (1st press water injection ON, 2nd press water injection OFF) might look like?

Many thanks in advance,

Chris

Edited by Chris455

  • Commercial Member
24 minutes ago, Chris455 said:

INSTRUMENT_SWITCH_Waterinjection_Set

What is that? LVar, BVar, IE - ??? The type is missing, and without it, this string tells us nothing. 

First thing to learn is proper syntax concerning variables and events. Otherwise all attempts at scripting will end in pain.

The AAO manual has an extensive chapter about Scripting, and there is a small introduction in the MSFS SDK documentation too.

Reverse Polish Notation

Edited by Lorby_SI

LORBY-SI

  • Author

So sorry,

It is an IE-

Can I make a script from an IE?

  • Commercial Member
9 minutes ago, Chris455 said:

So sorry,

It is an IE-

Can I make a script from an IE?

You can make scripts with anything. 

For a toggle you will have to find out how to read the value of the IE. In my experience it is better to use it as a BVar instead (IEs can be written either way)

Assuming that the value range is exactly 0 and 1, then the toggle script would look like this

1 (B:INSTRUMENT_SWITCH_Waterinjection) - (>B:INSTRUMENT_SWITCH_Waterinjection_Set)

"Read the value of the BVar and subtract it from 1, then write the result back into the BVar" This will make the var alternate between 0 and 1 every time the script is called.

Since I don't have that aircraft I cannot know if my script is correct or comment on how to do this with the IE itself. IEs are always aircraft specific, and I have no way of knowing how to get the value of that IE. Only you can do that in MSFS's developer mode or in AAO with the tools in the "Scripting" menu.
Here are some alternatives:
1 (IE:INSTRUMENT_SWITCH_Waterinjection_Set) - (>IE:INSTRUMENT_SWITCH_Waterinjection_Set)

or

1 (B:INSTRUMENT_SWITCH_Waterinjection_Set) - (>B:INSTRUMENT_SWITCH_Waterinjection_Set_Set)

or

try assigning B:INSTRUMENT_SWITCH_Waterinjection_Set_Toggle or B:INSTRUMENT_SWITCH_Waterinjection_Toggle directly to your button.

When you open an IE in the event list you will find the BVars attached as sub-nodes

Edited by Lorby_SI

LORBY-SI

  • Author

B:INSTRUMENT_SWITCH_Waterinjection_Set_Toggle - this did the trick, Thank you!

To toggle a variable from 1 to 0 or 0 to 1 this operation works well:

(V:TheVariable) ! (>V:TheVariable) This basically reads the variable then flips its binary value and writes it back to the same variable

Edited by mrm0508

WW5130.png

| i7-14700KF - 4080 SUPER | 32 GB RAM | Win 11 Pro | HC Bravo | AAO | StreamDeck | 

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.