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.

If..else statement syntax

Featured Replies

I am very new to XML programming and have managed so far using other peoples examples as a starting point. However, I have just got stuck here because I can't fathom out the syntax for if--els statements. the following code always works to switch OFF the fuel selector, but will not switch it back on again when the selector switch is clicked. I suspect there is one character wrong somewhere. can someone help please?(G:Var1,bool)(G:Var1) ! (>G:Var1) if {1 (>K:FUEL_SELECTOR_OFF) } els {(>K:FUEL_SELECTOR_ALL) }Peter

  • Author

Hi,Try something like:(G:Var1) 0 == if{ 1 (>G:Var1) (>K:FUEL_SELECTOR_ALL) } els{ 0 (>G:Var1) (>K:FUEL_SELECTOR_OFF) }NB May be better to use a L:Var: (L:Fuelselector,enum) 0 == if{ 1 (>L:Fuelselector,enum) (>K:FUEL_SELECTOR_ALL) } els{ 0 (>L:Fuelselector,enum) (>K:FUEL_SELECTOR_OFF) }Hope it helps, Jan"Beatus ille qui procul negotiis..."

Jan

 

 

 

"Beatus ille qui procul negotiis..."

Hi Peter,See also Jan's advice above.In your code you make two principle errors:1.(G:Var1) ! (>G:Var1) if....The test condition is now undefined:- (G:Var1) places the var on the stack- ! inverts this value- (>G:Var1) removes the value from the stackSo the testcondition is an old (undefined) value on the stack.(G:Var1) d ! (>G:Var1) if....would do what you want. ("d" duplicates the last stack value)2. Never put a space character between "if {" and "els {" !So use if{ and els{ Cheers, Rob Barendregt

Both of you were very helpful, and brought to an end days of head scratching! I still needed to toggle the switch bitmaps on the panel though, so the correct solution was as follows.(G:Var1) ! (>G:Var1) //toggles the switch on the panel(G:Var1) 1 == //tests value of G:Var1if{ 1 (>K:FUEL_SELECTOR_ALL) } //G:Var1 = 1 so switch on fuel. els{ 0 (>K:FUEL_SELECTOR_OFF) }//G:Var1=0 so switch off fuel.It works exactly correctly with the above code, but I would like your views on my understanding of what's happening as shown in the //comments.Finally, because I have a start button for the engine, and being a purist I want to always force a proper startup, is there a way to disable the Control-E autostart function when entered from the keyboard. The function tests for a keypress (or combination) but I want it then to do nothing. Any ideas.sort of - Peter

>>and being a purist ......Why ?? Because, yes, you can disable the "Control-E" keystroke (just remove the "(do nothing)" ), but who's to say that the pilot is using the default "Control-E" keystroke for this autostart function ??(in fact, I don't :-) )Cheers, Rob

Oh! I just want to make sure no-one who flies this aircraft cheats and doesn't use the gauge I have sweated over! :)Peter

  • Author

Hi,May be not necessary any more, but a rewrite of your gauge:(G:Var1)(G:Var1) 0 == if{ 1 (>G:Var1) (>K:FUEL_SELECTOR_ALL) } els { 0 (>G:Var1)(>K:FUEL_SELECTOR_OFF) } Jan"Beatus ille qui procul negotiis..."

Jan

 

 

 

"Beatus ille qui procul negotiis..."

Yes that's a bit neater, I'll use that. I did get close to that in my own efforts at one stage.Does (G:Var1) 0 == mean"Set G:Var1 to value 1" or "Is (G:Var1) is equal to 0? True or false"I seem to remember from my old C (DOS) programming days many many moons ago that x=1 and x==1 meant entirely different things. x=1 was actually a question which produced a true or false result, whereas x==1 meant "Make x=1".Seeing your latin quotation reminds me that I once saw a C programme written entirely in latin. The header file had a lot of defines in it! Quite fun. I'm intrgued enough to ask - does it mean "Blessed are the peace makers?Peter

  • Author

Hi,When the sim starts, or when you reload the sim or resize the window, or with 0 (>G:Var1), (G:Var1) becomes 0.That is why i advice to use (L:Var,enum).1 (>G:Var1) of course makes it 1.1033 (>G:Var1) means: (G:Var1)becomes 1033.I a string, %((G:Var1))%!d! , you read 1033. etcThe quote is from Horatius, just Google.........Jan

Jan

 

 

 

"Beatus ille qui procul negotiis..."

  • Moderator

>I seem to remember from my old C (DOS) programming days many>many moons ago that x=1 and x==1 meant entirely different>things. x=1 was actually a question which produced a true or>false result, whereas x==1 meant "Make x=1".Actually, it's just the opposite... ;)In C, a double equals "==" is a question, a single equels "=" is an assignment.int x;if (x == 1) { x = 0 ; }In XML, a single equals has no real meaning at all, but the double equals "==" means the same as in C.(L:x,bool) 1 == if{ 0 (>L:x,bool) }

Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

>>I seem to remember from my old C (DOS) programming days>many>>many moons ago that x=1 and x==1 meant entirely different>>things. x=1 was actually a question which produced a true or>>false result, whereas x==1 meant "Make x=1".>>Actually, it's just the opposite... ;)>>In C, a double equals "==" is a question, a single equels "=">is an assignment.>>int x;>>if (x == 1) { x = 0 ; }>>In XML, a single equals has no real meaning at all, but the>double equals "==" means the same as in C.>>(L:x,bool) 1 == if{ 0 (>L:x,bool) }I said it was a long time ago - 15 years approx. I think. However, little snippet has helped my understanding of XML syntax along a bit further.Peter

  • Author

See upstairs, As a `purist` too i use :(>K:ABORT) Jan"Beatus ille qui procul negotiis..."

Jan

 

 

 

"Beatus ille qui procul negotiis..."

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.