Jump to content
Sign in to follow this  
Varmint007

Understanding if..else in XML

Recommended Posts

Guest depot_haldol

This is giving me a headache. Instead of just having someone help with my code, I'd love it if someone could write a short paragraph explaining how if..else syntax works in XML. I've searched the forum and there are plenly of posts that give some examples, but nothing is exactly like what I'm doing so I'm hoping for some extra help and maybe some theory.I have good working code that tests one condition. How can I test two conditions? Here's what I have so far:(L:CockpitState, enum)What I'd like to do is display the image if CockpitState is "0" AND (L:Power, bool) is equal to 1.Should I try to incorporate this into an if{} statement? If so, what are the rules for syntax? Or should I try to make a complicated statement, and if that's the case, then does it matter if one variable is type enum and the other is type bool? Thanks gurus.---Will

Share this post


Link to post
Share on other sites
Guest Vorlin

This is my rubber stamp code to test if something is between min and max values set... it can be cusomized for your needs:<Visible>(VALUE, UNIT) MaxValue <=(VALUE, UNIT) MinValue >= &-a-m-p-;&-a-m-p-;</Visible>(Get rid of the dahses in the &-a-m-p-;&-a-m-p-;... the forum won't display that word without them for me)Instead of setting min and max, just change it to two boolean statements:<Visible>(L:CockpitState, enum) 0 ==(L:Power, bool) &-a-m-p-;&-a-m-p-;</Visible>Remember, it's reverse polish notation. The above reads:1) L:CockpitState and 0 are Equal2) L:Power (by itself tests to see if it's true)3) &-a-m-p-;&-a-m-p-; is the way we write && (boolean test for AND) because a lot of the symbols have other meanings in XML and those other meanings tend to mess things up.If your cockpit state has only two possibilities (true and false), you can change it to:(L:CockpitState, BOOL) !This is simply a test for true followed by a NOT.Who would have thought that studying JK flip flops and boolean algebra 20 years ago would have any value now? (grin)I guess we never really know.Good luck with the rest of it,Scott / Vorlin

Share this post


Link to post
Share on other sites
Guest depot_haldol

If I "declare" an L:variable as type enum in one gauge, can it be used as (L:variable, bool) on another gauge, provided the value at the time is either 0 or 1?Also, the code snippet you posted above:(L:CockpitState, enum) 0 ==(L:Power, bool) &-a-m-p-;&-a-m-p-;...means my image will be visible if (CockpitState = 0) and (Power = 1). Got it. Can I add even more tests to the list? Like:(L:CockpitState, enum) 0 ==(L:Power, bool) &-a-m-p-;&-a-m-p-(L:AnotherTest, bool) &-a-m-p-;&-a-m-p-;Also: Do I use the same notation inside a command to execute the Click event only when certain conditions are true? Let's say I wanted the Click event to execute only when (CockpitState = 1) and (Power = 0). The click event itself would be some random (>K:KEY_COMMAND). What would that look like?And finally, since you're so patient and helpful, what's the practical difference between using statements like these and using if{ els{ notation? Thanks a million; you all are slowly helping me understand this quite insane programming syntax.---Will

Share this post


Link to post
Share on other sites

Hi,Correct.You can use as many statements, if's and els' as you need.More simple to use is the synthax "and", so in one click:...(statement0,bool) ! (statement1,bool) (statement2,enum) 61 == (statement3,enum) 0 == (G:Var1) 0 == (G:Var9) 372 == etc.and and and and and etc. if{ (Whatever Command) } ...Other commands you need....Jan"Beatus ille qui procul negotiis..."

Share this post


Link to post
Share on other sites
Guest depot_haldol

Thanks guys. I'll play around with it tonight and see if I can get my code to work. Thanks for the help.---Will

Share this post


Link to post
Share on other sites

""If I "declare" an L:variable as type enum in one gauge, can it be used as (L:variable, bool) on another gauge""Yes, because as weird as it sounds, "bool-number-enum" units support any number (pos/neg).""provided the value at the time is either 0 or 1?""Almost exactly.To clarify:25 (>LVar,enum) or 25 (>LVar,bool)(LVar,bool) 25 == is true (1) (LVar,bool) if{ this cond is executed } Just to understand the second example, (Any value or VarValue) if{ the code will go through here as long as the value is >=1 or <=-1 } els{ this is executed otherwise }All this said, I would recommend to stick to the original unit (number or bool) as to avoid a logical distortion.Tom

Share this post


Link to post
Share on other sites
Guest Vorlin

Jan... I'm glad to hear that "and" still works. I'd seem some examples with it and thought that they might have been hold overs from FS2002 or something since many people have been saying to use &-a-m-p. If "and" is still viable, it will sure make life easier! Thanks!Tom... Thanks for that info on typing. I think from here on I'll type everything either number or enum and test for true with :(L:MyVar, number) 1 ==Thanks to you too!Scott / Vorlin

Share this post


Link to post
Share on other sites
Guest N66FC Raptor

[strong]Question?[/strong]   Where does the [span style=color: red]

<Visible>

[/span] tag go, in the XML code? For example: Preceeding the

Value

, following the

Value

, or does the

<Visible>

tag replace the

Value

tag?[br][br]

<Select>[br]    [span style="color: red;"]<Visible> ... </Visible>[/span][br]    <Value> ... </Value>[br]        . . .[br][br]<Select>[br]    <Value> ... </Value>[br]    [span style="color: red;"]<Visible> ... </Visible>[/span][br]        . . .[br][br]<Select>[br]    [span style="color: red;"]<Visible> ... </Visible>[/span][br]        <Case Value="0">[br]            . . .

Share this post


Link to post
Share on other sites
Guest Vorlin

Visible tags have successfully been used in:This is according to a DTD that I assembled from over 20,000 lines of working XML code (Yes, I made sure that I used only one gauge, mouse, update and keys section each.)For your use above, you would need to use: When it's visible Vorlin

Share this post


Link to post
Share on other sites

>might have been hold>overs from FS2002 or something since many people have been>saying to use &-a-m-p. If "and" is still viable, it will sure>make life easier! Thanks!Actually it's just the opposite. 'and' became kosher in FS9, but won't work in FS8. '>' also works in FS9, but '<' will still get you into trouble.--Jon

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  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...