Sign in to follow this  
phjvh

If..else statement syntax

Recommended Posts

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

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

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..."

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

>>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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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..."

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

>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) }

Share this post


Link to post
Share on other sites

>>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

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this