View Full Version : XML-Question: codes for "and" and "or"
Schindi
10-21-2007, 01:32 PM
Hi all!
I want to create a gauge where a certain image is shown when two conditions are met, namely Generator1 OR Generator2 are active, but not when both are active.
So if I switch on Gen1 the light goes on, when I turn also on Gen2 it goes out and if I switch Gen1 off again it goes on again..
I tried with the following code (it's just the part that matters, I think), but got no luck: the image is on no matter wheter one or both generators are running:
<Value>(A:GENERAL ENG1 GENERATOR ACTIVE,bool)(A:GENERAL ENG2 GENERATOR ACTIVE,bool) &&</Visible>>
<Case Value="0">
<Image Name="Console_right_caution_GENTIE.bmp" Luminous="Yes" ImageSizes="166,152"/>
</Case>
Could anyone be so kind as to tell me what I do wrong and/or (here we go again) explain to me the different possibilities we have to tell a gauge to "do this if that and that happens", or "do that if this but not that happens"?
Thanks in advance for any info! = )
n4gix
10-21-2007, 03:17 PM
First, you have placed a </Visible> tag in the middle of a <Value>...</Value> tag pair. This is not correct.
This is a correctly formed AND condition:
<Visible>
(A:GENERAL ENG1 GENERATOR ACTIVE,bool)
(A:GENERAL ENG2 GENERATOR ACTIVE,bool)
&&
</Visible>
This is the OR condition:
<Visible>
(A:GENERAL ENG1 GENERATOR ACTIVE,bool)
(A:GENERAL ENG2 GENERATOR ACTIVE,bool)
||
</Visible>
Note also that you can substitute "and" for the "&&" symbols, and an "or" for the "||" symbols... ;)
Schindi
10-22-2007, 02:30 PM
Thanks Bill for the response!
I tried with various different ways (and with correcting my typo you mentioned...), but still no luck.
I also tried using the visible-tag (then without the select- and value-tags), I tried playing around with the case value (0, 1, even 2), I tried also with OR instead of AND.... no joy...
Depending on which variant I use the bimap either stays on or off, no matter if one or two generators are running. = (
This is how the whole gauge looks atm:
<Gauge Name="ms_RightCaution" Version="1.0">
<Image Name="Console_right_caution_background.bmp" ImageSizes="166,152"/>
<Element>
<Select>
<Value>
(A:GENERAL ENG1 GENERATOR ACTIVE,bool)
(A:GENERAL ENG2 GENERATOR ACTIVE,bool) and
</Value>
<Case Value="0">
<Image Name="Console_right_caution_GENTIE.bmp" Luminous="Yes" ImageSizes="166,152"/>
</Select>
</Element>
</Gauge>
As I understand it in this case if gen1 AND gen2 run the value is 1, and thus the "GENTIE" bitmap doesn't show, whereas wif only gen 1 or only gen2 run the value would be 0 and thus the bitmap would show, right?
Or is my logic flawed (quite usual case for me actually, haha)?
Cheers,
Schindi
n4gix
10-22-2007, 03:37 PM
No, the logic will always return "1" if the <Value> expression is "true."
The following will display the image ONLY if both generators are turned on. If you want the image to only show if one of the generators are on, simply change the "and" to an "or":
<Gauge Name="ms_RightCaution" Version="1.0">
<Image Name="Console_right_caution_background.bmp"/>
<Element>
<Select>
<Value>
(A:GENERAL ENG1 GENERATOR ACTIVE,bool)
(A:GENERAL ENG2 GENERATOR ACTIVE,bool)
and
</Value>
<Case Value="1">
<Image
Name="Console_right_caution_GENTIE.bmp"
Luminous="Yes"
/>
</Case>
</Select>
</Element>
</Gauge>
You can use WinZip to "unCAB" the Beech_Baron.cab file to a folder and then look at the XML examples in that folder to see how these gauges are constructed... ;)
Schindi
10-22-2007, 06:22 PM
Thanks again Bill for your insights!
Well, with your info and some additional trial and error I finally got it to work as I wanted.
My mistake was that I assumed the logic to be independent of the order of the two outputs.
But what I learned now is that the order indeed matters a lot! So actually I had to duplicate the element, but with inverted order of the generators!
a) if gen1 on and gen2 off, then value=0
b) if gen2 on and gen1 off, then value=0
=> Result: Light is off only if both generators are running and on if only one of them has been started! Tadaaa!!!
:D
taguilo
10-23-2007, 11:21 AM
>
>Depending on which variant I use the bimap either stays on or
>off, no matter if one or two generators are running. = (
>
>This is how the whole gauge looks atm:
>
><Gauge Name="ms_RightCaution"
>Version="1.0">
><Image
>Name="Console_right_caution_background.bmp"
>ImageSizes="166,152"/>
><Element>
><Select>
><Value>
>(A:GENERAL ENG1 GENERATOR ACTIVE,bool)
>(A:GENERAL ENG2 GENERATOR ACTIVE,bool) and
></Value>
><Case Value="0">
><Image Name="Console_right_caution_GENTIE.bmp"
>Luminous="Yes" ImageSizes="166,152"/>
></Select>
></Element>
></Gauge>
>
>As I understand it in this case if gen1 AND gen2 run the value
>is 1, and thus the "GENTIE" bitmap doesn't show,
>whereas wif only gen 1 or only gen2 run the value would be 0
>and thus the bitmap would show, right?
>
Your example is pretty right, the problem is that you forgot to close the </Case> before the </Select>, hence it shows always the first defined image ( "Console_right_caution_background.bmp" )
In fact, this is a good solution in those cases where you need to test for a multiple false condition and only one true:
Pseudocode
<Image when true = Image1> (* displays by default *)
<Select>
<Value>cond1 on cond2 on and</Value>
<Case Value="0"> (*If value is false, displays image2 "over" image1*)
<Image when false = Image2>
</Case>
etc..
Instead of doing "cond1 on cond2 off and cond 2 off ccond 1
on and...etc"
Tom
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.