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.

Launch batch file when click a switch in the virtual cockpit

Featured Replies

Hello Lorby,

I would like to know if is possible to automatically launch a batch file when I click a switch in the virtual cockpti of a plane.

And if yes how to do that.

Thank you.

Edited by whityini

  • whityini changed the title to Launch batch file when click a switch in the virtual cockpit
  • Commercial Member

In AAO you use the (EXECBAT: command, see AAO manual around page 83 "AAO specific RPN commands".

But "click on a switch in the cockpit" can have many different consequences, and only very few of them can be observed from the outside by AAO. Essentially the sim only "reports" K: events and IEs over SimConnect. For those you can use the (LISTEN_FOR_RPN or (LISTEN_FOR_K script headers to catch whatever is being sent from your switch.

If the switch doesn't send anything that you can observe, that would mean that you have to alter the switches' code in the sim to make that happen. Are you the developer of the aircraft? Ideally you would add a bit of Javascript to access the AAO WebAPI and send the EXECBAT command directly.

Edited by Lorby_SI

LORBY-SI

  • Author

I am not a developer, just a user.

I already have the batch file that actually I start manually when the iFly 737 is loaded.

I would like to intercept the variable L:VC_Battery_SW_VAL (the batteries switch) to laungh the batch automatically

  • Commercial Member
1 hour ago, whityini said:

I am not a developer, just a user.

I already have the batch file that actually I start manually when the iFly 737 is loaded.

I would like to intercept the variable L:VC_Battery_SW_VAL (the batteries switch) to laungh the batch automatically

You cannot "intercept" an LVar - they are just values, stored in the sim under this name. If this LVar keeps its value, you can write an Autoscript that compares it with your own reference value and then triggers some code of your own design - like calling a batch file. But if the aircraft designer chose to only use the LVar momentarily, this won't work. You will have to try, there is no knowing this in advance.

You would create a script like this and save it.

(L:VC_Battery_SW_VAL, Number) (L:MyBatRef) != if{ (L:VC_Battery_SW_VAL, Number) 10 == if{ (SPEAK:on) } (L:VC_Battery_SW_VAL, Number) (>L:MyBatRef) }

Then use Scripting->Aircraft automated Scripts to run it every 500ms or something. Then, every time you turn on the battery (or rather, flip the switch to "on"), your computer will say "on" - that's what the SPEAK command does. Replace the SPEAK command with whatever you need, probably EXECBAT - see AAO manual.

Be mindful that this is just off the top of my head. None of this is tried or tested.

Edited by Lorby_SI

LORBY-SI

  • Author

Thank you Lorby for your help.

I have changed the script, but in this case the bat is executed all the time I load the airplane. Could you please check what is wrong?

//·Script:·Check_And_Run_Batch

//·Initialize·var·to·10·if it doesn't exixt

(L:MyVarBat,·Number)·0·==·if{

····10·(>L:MyVarBat,·Number)

}

//·Read the variable in the sim

(L:VC_Battery_SW_VAL,·Number)·(L:MyVarBat,·Number)·==·if{

····//·Run the·file·batch

····(EXECBAT:C:\myfile.bat)

····//·Update·var·to·20

····20·(>L:MyVarBat,·Number)

}

THK

  • Commercial Member
1 hour ago, whityini said:

Thank you Lorby for your help.

I have changed the script, but in this case the bat is executed all the time I load the airplane. Could you please check what is wrong?

//·Script:·Check_And_Run_Batch

//·Initialize·var·to·10·if it doesn't exixt

(L:MyVarBat,·Number)·0·==·if{

····10·(>L:MyVarBat,·Number)

}

//·Read the variable in the sim

(L:VC_Battery_SW_VAL,·Number)·(L:MyVarBat,·Number)·==·if{

····//·Run the·file·batch

····(EXECBAT:C:\myfile.bat)

····//·Update·var·to·20

····20·(>L:MyVarBat,·Number)

}

THK

I'm sorry, but I have no idea what you are doing there. Why aren't you just using my script?

  1. Lose the // comments. They are bad form and only slow down processing for no purpose. You know what your own script is doing, you don't need a comment to tell you.

  2. (L:MyVarBat) is AAO internal, it doesn't have a unit. Lose the ", Number"

  3. (L:MyVarBat) MUST always have the same value as the (L:VC_Battery_SW_VAL,·Number). It serves as a reference, so the script knows when the Battery LVar from the sim has changed. OK? That's the whole "trick" here, it prevents the script from just running every time. You cannot just set it to whatever value you want (why 10? why 20?)

  4. LVars don't have to be initialized. Their life begins when they are first used in code. So (L:MyVarBat) is 0 every time AAO is initialized (restarted/connected to the sim/a script is alterted/ etc.)

Edited by Lorby_SI

LORBY-SI

  • Author

Sorry, maybe I was not so clear. I need that the batch should be executed only once on the first click of the battery switch.

  • Commercial Member
17 minutes ago, whityini said:

Sorry, maybe I was not so clear. I need that the batch should be executed only once on the first click of the battery switch.

As I wrote above, you cannot catch the "click", that is not possible with LVars. You can only react to the animation LVar changing its value (=observing the result of the click - that is not the same).

Please specify what "the first click" actually means. Do you mean every change of the switch = both ON and OFF direction? Or only "ON" because you always start in cold and dark mode?

Edited by Lorby_SI

LORBY-SI

  • Author

Only on the first ON because i always start c&d.

  • Commercial Member
6 minutes ago, whityini said:

Only on the first ON because i always start c&d.

I would still use my autoscript. Since the battery LVar apparently has 10 as the "ON" value, the script would look like this:

(L:VC_Battery_SW_VAL, Number) (L:MyBatRef) != if{ (L:VC_Battery_SW_VAL, Number) 10 == if{ (EXECBAT:C:\myfile.bat) } (L:VC_Battery_SW_VAL, Number) (>L:MyBatRef) }

This script will always start the batch file every time the Battery switch goes from OFF to ON. It will also start the batch file when you connect AAO after you've already switched to "ON", because that is the state that it is looking for.

Initially, both LVars are 0, so the script won't fire. When you click the battery switch ON, the LVar changes to 10 and the if is executed. And since you only want to start the batch when the battery is turned on, the script checks for the value "10".

There are probably a dozen other ways to script this, and there are alternatives too. You could create a CONVERSATION type script file and start this when you start your flight. In such a file you can make the logic wait for certain things to happen, then proceed with doing other stuff. AAO users are implementing thier own first officer and/or flight attendant with this technique. In this case, the line that waits for the battery switch would look like this:

(...some code...)

[(L:VC_Battery_SW_VAL, Number) 10 ==] (EXECBAT:C:\myfile.bat)

(...more code...)

That CONVERSATION you start at the beginning of your flight (via Autoscript), and it will wait for the battery switch.

Edited by Lorby_SI

LORBY-SI

  • Author

Thank you Lorby the script works perffectly.

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.