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.

JScript question

Featured Replies

I am trying to find a graceful way to read an MSFS LVAR, then based on the result, write a different AVAR value, and also change the value of the first LVAR.

A button press in MSFS results in L:Payload_Station:13 being set to "1".  A separate button press in MSFS results in A:Payload Station Weight:13 being set to "2010".  Both of those features work fine  I want to write a script that can be mapped to a joystick button that when pressed, reads several payload station LVARs, then for each one that has a value of 1, set the corresponding Payload Station Weight AVAR value to 0, and set the original LVAR back to 0.  In essence it reads what stations have been loaded, then armed, then simulates dropping ordinance by changing the loaded weight to 0.

I have looked at JScript, this is what I came up with but unsurprisingly it doesn't work, any advice would be appreciated.

 

(WSH:jscript|AaoEntry)

function AaoEntry(){

if ((L:Payload_Station:13 = 1))  
    theReaction = (((A:Payload Station Weight:13).exec(0)) && ((L:Payload_Station:13).exec(0)));

else   

if ((L:Payload_Station:11 = 1))  
    theReaction = (((A:Payload Station Weight:11).exec(0)) && ((L:Payload_Station:11).exec(0)));
    }   

 

 

Thanks

Mike

  • Commercial Member

I'm sorry, but I don't understand what you are trying to do. The above is not a language that I can recognize.

Just be mindful that this is still JScript (=Javascript syntax applies) and the Variables must still be written correctly (the AVar was/is wrong?). No experiments.

This is what I think you were trying to achieve?

(WSH:jscript|AaoEntry)

function AaoEntry(){
  if ((L:Payload_Station_13) == 1){  
    (A:Payload Station Weight:13, Pounds) = 0;
	(L:Payload_Station_13) = 0;
  } else {
	if ((L:Payload_Station_11) == 1){
    	(A:Payload Station Weight:11, Pounds) = 0; 
		(L:Payload_Station_11) = 0;
    }
  }
}

 

 

Edited by Lorby_SI

LORBY-SI

  • Commercial Member

Here the classic RPN code (JScript seem like a bit of an overkill)

Quote

(L:Payload_Station_13) 1 == if{ 0 (>A:Payload Station Weight:13, Pounds) 0 (>L:Payload_Station_13) } els{ 
(L:Payload_Station_11) 1 == if{ 0 (>A:Payload Station Weight:11, Pounds) 0 (>L:Payload_Station_11) } }

Is that "else" really what you want? Clear the one station but not the other? Shouldn't the script just check all station LVars?

Quote

(L:Payload_Station_13) 1 == if{ 0 (>A:Payload Station Weight:13, Pounds) 0 (>L:Payload_Station_13) }
(L:Payload_Station_11) 1 == if{ 0 (>A:Payload Station Weight:11, Pounds) 0 (>L:Payload_Station_11) }

or in JScript

(WSH:jscript|AaoEntry)

function AaoEntry(){
  if ((L:Payload_Station_13) == 1){  
    (A:Payload Station Weight:13, Pounds) = 0;
	(L:Payload_Station_13) = 0;
  }
  if ((L:Payload_Station_11) == 1){
    (A:Payload Station Weight:11, Pounds) = 0; 
	(L:Payload_Station_11) = 0;
  }
}

Edited by Lorby_SI

LORBY-SI

  • Author

Thanks for taking a look at this.  There are actually 5 total payload stations that I would like the one script to look at (stations 9, 10, 11, 12 & 13), then for each that =1, execute the setting of weight back to 0 and then adjust the initial 1 back to 0.  

Edited by MikeWest

  • Author

It could be only 1 station set that needs to be cleared, or it could be all 5.

 

  • Commercial Member
(L:Payload_Station_9)·1·==·if{·0·(>A:Payload·Station·Weight:9,·Pounds)·0·(>L:Payload_Station_9)·}·
(L:Payload_Station_10)·1·==·if{·0·(>A:Payload·Station·Weight:10,·Pounds)·0·(>L:Payload_Station_10)·}·
(L:Payload_Station_11)·1·==·if{·0·(>A:Payload·Station·Weight:11,·Pounds)·0·(>L:Payload_Station_11)·}·
(L:Payload_Station_12)·1·==·if{·0·(>A:Payload·Station·Weight:12,·Pounds)·0·(>L:Payload_Station_12)·}·
(L:Payload_Station_13)·1·==·if{·0·(>A:Payload·Station·Weight:13,·Pounds)·0·(>L:Payload_Station_13)·}

This is one single RPN script. No need for JScript just for this IMHO.

LVar names have to change, like in my script. Indexes are not allowed in local variables.

Edited by Lorby_SI

LORBY-SI

  • Author

Thank you very much for your help.  I wasn't able to get it to work directly with your example, but I was able to modify it to do what I wanted, I had to split the weight reset and the station selection reset code into separate lines.  Not quite sure why, but it works.

 

(L:Payload_Station_9,·number)·0·(L:Payload_Station_9,·number)·1·==·if{·0·(>A:Payload·Station·Weight:9,·Pounds)··}
(L:Payload_Station_10,·number)·0·(L:Payload_Station_10,·number)·1·==·if{·0·(>A:Payload·Station·Weight:10,·Pounds)··}··
(L:Payload_Station_11,·number)·0·(L:Payload_Station_11,·number)·1·==·if{·0·(>A:Payload·Station·Weight:11,·Pounds)··}·
(L:Payload_Station_12,·number)·0·(L:Payload_Station_12,·number)·1·==·if{·0·(>A:Payload·Station·Weight:12,·Pounds)··}·
(L:Payload_Station_13,·number)·0·(L:Payload_Station_13,·number)·1·==·if{·0·(>A:Payload·Station·Weight:13,·Pounds)··}·
(L:Payload_Station_9)·0·(>L:Payload_Station_9,·number)
(L:Payload_Station_10)·0·(>L:Payload_Station_10,·number)
(L:Payload_Station_11)·0·(>L:Payload_Station_11,·number)
(L:Payload_Station_12)·0·(>L:Payload_Station_12,·number)
(L:Payload_Station_13)·0·(>L:Payload_Station_13,·number)

  • Commercial Member
19 minutes ago, MikeWest said:

Not quite sure why, but it works.

My script above is definitely working, I've tested it just now. You must have either had a typo in the script or the variables are/were wrong.

Question 1: why the ", Number" Unit? Are the LVars coming from the simulator? This is a key question, see observation below.
Question 2: your script contains a lot of unnecessary code. Why? "(L:Payload_Station_x,·number)·0" in the first lines do absolutely nothing. "(L:Payload_Station_x)" in the lower lines is also not doing anything at all.

Observation: (L:Payload_Station_9) and (>L:Payload_Station_9, Number) are not the same - these are two different variables. The first never leaves AAO, the second is synchronized with the sim. For the AAO app both are different assets, either use one or the other, depending on your use case. They are not interchangeble.

Edited by Lorby_SI

LORBY-SI

  • Author

The LVARS are coming from the simulator and need to be written back to the simulator, the AAO MSFS Document says the unit needs to be annotated since it is an LVAR from the sim, and it only worked when I added it. When I pasted in your code above, it didn't work for me unfortunately, the weight wasn't being written back to the sim for just the payload stations with a value of 1,  and the value of the payload station with a value of 1 was not being reset to 0.  I thought my first 5 lines alone should work but they didn't.  Adding the last 5 lines did.

 

  • Commercial Member
50 minutes ago, MikeWest said:

it didn't work for me unfortunately,

Because in my script they were local variables - you didn't tell me that they were coming from/going to the sim. You just have to add the ", Number" to them. What are those LVars doing in the sim?

(L:Payload_Station_9,·Number)·1·==·if{·0·(>A:Payload·Station·Weight:9,·Pounds)·0·(>L:Payload_Station_9,·Number)·}·
(L:Payload_Station_10,·Number)·1·==·if{·0·(>A:Payload·Station·Weight:10,·Pounds)·0·(>L:Payload_Station_10,·Number)·}·
(L:Payload_Station_11,·Number)·1·==·if{·0·(>A:Payload·Station·Weight:11,·Pounds)·0·(>L:Payload_Station_11,·Number)·}·
(L:Payload_Station_12,·Number)·1·==·if{·0·(>A:Payload·Station·Weight:12,·Pounds)·0·(>L:Payload_Station_12,·Number)·}·
(L:Payload_Station_13,·Number)·1·==·if{·0·(>A:Payload·Station·Weight:13,·Pounds)·0·(>L:Payload_Station_13,·Number)·}

Be mindful that variables are case sensitive too. They have to be absolutely identical everywhere. (L:PAYLOAD) and (L:payload) are two different variables for AAO.

Edited by Lorby_SI

LORBY-SI

  • Commercial Member
38 minutes ago, MikeWest said:

I thought

Scripts don't work on thoughts. You have to get the RPN syntax down, and it must be spot on perfect, or your scripts will only work by accident. AAO RPN is not forgiving in the slightest - because of performance considerations the parser is as stripped down as possible, it won't tolerate any code errors. 

Your script without the parts that don't do anything:
 

(L:Payload_Station_9,·number)·1·==·if{·0·(>A:Payload·Station·Weight:9,·Pounds)·}·
(L:Payload_Station_10,·number)·1·==·if{·0·(>A:Payload·Station·Weight:10,·Pounds)·}·
(L:Payload_Station_11,·number)·1·==·if{·0·(>A:Payload·Station·Weight:11,·Pounds)·}·
(L:Payload_Station_12,·number)·1·==·if{·0·(>A:Payload·Station·Weight:12,·Pounds)·}·
(L:Payload_Station_13,·number)·1·==·if{·0·(>A:Payload·Station·Weight:13,·Pounds)·}·
0·(>L:Payload_Station_9,·number)·
0·(>L:Payload_Station_10,·number)·
0·(>L:Payload_Station_11,·number)·
0·(>L:Payload_Station_12,·number)·
0·(>L:Payload_Station_13,·number)


 

 

Edited by Lorby_SI

LORBY-SI

  • Author

Sorry I wasn't clear in my initial post where the very first line says "I am trying to find a graceful way to read an MSFS LVAR, then based on the result, write a different AVAR value, and also change the value of the first LVAR." and then I said "A button press in MSFS results in L:Payload_Station:13 being set to "1"", to me that means the the variable starts in the sim and is a sim variable not a local variable.  The LVARs Payload_Station_x when set to 1 tell the aircraft avionics that there is ordinance loaded on that station and available to be armed for dropping.  Anyway, it works now, you have been a great help pointing me in the right direction as I was starting in JScript for this instead of RPN, and even giving some hints on cleaning up code.

  • Commercial Member
13 hours ago, MikeWest said:

to me that means the the variable starts in the sim and is a sim variable not a local variable. 

And yet in your code they all were local variables...

btw. there used to be other AVars where you could attach a simobject to a payload station which could then be dropped with a K: event. Wonder what happened to them in MSFS?

LORBY-SI

Archived

This topic is now archived and is closed to further replies.

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.