• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

<visible> useage clairification

Messages
137
Country
us-southcarolina
All,

I'm at a point in my project where I'm starting to put together control logic functions, switches etc in my HUD/panel. In my FSX adventures I have run into several instances where there were undocumented exceptions or differences with this or that feature/syntax etc, so i thought I would try to save myself some of those beat your head against the wall moments by asking a few seemingly simple/obvious questions upfront. I went through the usual FS9/FSX docs and just had a few clarification questions about using <visible> tag in controlling code execution. I got the part about <Visible>
needing to be contained in it's own <Element> tag.

1. If "<visible>" is false, does that prevent ANY and ALL code execution within the containing "<Element>", meaning does it, in affect, skip code until the "</Element>" closing tag, including all children ?

2. To be clear, If above is true then I assume that would also include the declaration/creation of any L:var etc,ie they would not be created if nested in code that was not "visible" ?

3. Is there a CPU savings by "tuning off" sections of code with "<visible>"?

4. Can <visible> be used to control code execution in an invisible gauge that is not ever visible in the panel ? Like say, for example, sound control gauge?

5. Can If/then statements be used with "<visible", ie other than setting the "Visible" condition itself can "if" and "else" be used to also set other Flags? if so would that syntax be something like
Code:
<Visible>
(L:varFlag1, bool)  (L:varState, number) 5 &lt; ||
if { (&gt; L:varFlag2, enum) 1 }
els{ (&gt;L:varsState, number) 0}
</Visible>
meaning.... if varFlag1 TRUE or if L:varState is less than 5, then "visible" and set L;varFlag2 to 1. If not... not "visible" and set L:varState to 0 ??

Thanks

Joel
 
Last edited:
Hi,

I did some testing.

1. No. Code in a Select/Value section was still executed, even if a Text section in the same Element was made not visible.

2. No. L: Vars are still initialized.

3. Since 1 and 2 are no, this is no.

4. I assume this is yes but only display sections, not other code (see 1 and 2 above).

5. The value is placed into the (L:varFlag2, enum), but then the Visible statement doesn't work.

BTW, you can even use Visible statements in Mouse (Area) sections to make mouse click areas disappear:

Code:
        <Area Left="20" Width="50" Height="96">
              <Visible> @Types 1 &gt; </Visible>
                  <Tooltip>Aircraft Select: %((L:AC_Type, number))%{case}%{:5}@Type6 %{:4}@Type5%{:3}@Type4%{:2}@Type3%{:1}@Type2%{:0}@Type1%{End}</Tooltip>
            <Cursor Type="Hand"/>
            <Click> @Types 1 &gt; if{ (L:AC_Type, number) @Types 1 - &lt; if{ (L:AC_Type, number) 1 + (&gt;L:AC_Type, number) } els{ 0 (&gt;L:AC_Type, number) } }</Click>
        </Area>
 
So if 1-3 are no. What method/tag can i use to control code execution that is not "Text" or display related? As in your answer 1,
1. No. Code in a Select/Value section was still executed, even if a Text section in the same Element was made not visible.
??
So if I had a Select/Value section that i did NOT want executed if the parent "visible" was false would i have to include the same conditional if/then/els use to evaluate the parent <Visible> ?

And the same for any other code i did not want executed ? :confused:

Joel
 
So if I had a Select/Value section that i did NOT want executed if the parent "visible" was false would i have to include the same conditional if/then/els use to evaluate the parent <Visible> ?

And the same for any other code i did not want executed ? :confused:

What's so undesirable about a simple conditional statement?
Code:
<Element>
<Select>
<Value>
(L:A,number) (L:B,number) &gt;
if{
...
}
</Value>
</Select>
</Element>

OR you can try to use a "quit" statement in your "False"/els{} condition, BUT I don't know whether it only stops execution of the remaining element or the entire gauge altogether (testing required!)!

(See the expression operator table here: https://msdn.microsoft.com/en-us/library/cc526953.aspx)
 
What's so undesirable about a simple conditional statement?
Code:
<Element>
<Select>
<Value>
(L:A,number) (L:B,number) &gt;
if{
...
}
</Value>
</Select>
</Element>

OR you can try to use a "quit" statement in your "False"/els{} condition, BUT I don't know whether it only stops execution of the remaining element or the entire gauge altogether (testing required!)!

(See the expression operator table here: https://msdn.microsoft.com/en-us/library/cc526953.aspx)

Nothing wrong with it as I assumed that is how i would have to do it. I was just hoping i could get a one stop shop out of the <visible> conditionals that would apply to the whole element and children. I's just extra coding and opportunity for me to muck it up ;)

I'll just need to do a full flow chart etc for all the controls to make sure nothing slips thru the cracks. I'm glad i ask ahead of time.

thanks

Joel
 
Try to be as explicit as possible, defining the exact conditions when something is to be true and the exact conditions when something is to be false. Unfortunate use of "els{}" statements, especially with a bunch of evaluations for the "if{ }" condition, is a prime source for bugs and unwanted behavior.
 
Unfortunate use of "els{}" statements, especially with a bunch of evaluations for the "if{ }" condition, is a prime source for bugs and unwanted behavior.

So is the inclusion of an "els" required ? meaning while it would be more wordy to do 2 exact but separate "If" statements, it would be worth it if it cut down on problems down the road. ??

or maybe a "els if" followed by nothing ??

Joel
 
Last edited:
Either way works fine - whichever is easier for you to understand and remember.
 
Either way works fine - whichever is easier for you to understand and remember.
I think it might be better for understanding my intent..... but remembering is a whole other issue all together ;), which brings me to another topic and that's the effectiveness and numerous of ways , there seems to be to "comment" xml code in FSX.
Code:
<comment> blah blah </comment>
<!-- blah blah -->
// blah blah  - same line only
(* blah blah *) - ?? just saw this the other day

While all seem to work for leaving comments of different lengths, their does seem to be a difference in each methods effectiveness in turning off or "parking" code sections or scripts for debugging.
The only one that seems to work 100% of the time is the "comment" tag. The one that is the easiest to read is <!-- abc --> since it changes the color of all containing code/text green (at least in my editor). I wish I could get "//" to turn what follows a different color but haven't found a way in NotePad++. Also there have been some cases where <!-- abc --> didn't work and it took a "Comment" tag to work.

Joel
 
I use method number two (<!-- ... -->) in XML gauges. Just looks best to me.
 
Each way to add comment (or comment out some code) in XML has it's quircks.
There are several threads about that in this forum.

Like:
Code:
<Comment> ....   <    (the smaller-then character) ........</Comment>

or

<!-- ......    --    (double minus sign, as used in "decrement" coding) .....-->
both dont work .
Just two examples.

Rob
 
As to using "goto" and "quit" in XML Value sections:
Yes, possible, but be very carefull :

Examples:
Code:
<Element>
<Select>
<Value>
:0
(G:Var1) ++ (&gt;G:Var1)
(G:Var1) 10 % 0 == if{ quit }
g0
</Value>
</Select>
</Element>
will increment Var1 10 times (within the same schedule !); the "quit" will exit the Element processing and continues with the next one.

BUT ,make sure the loop will indeed terminate, otherwise you will hang FS.
Like:
Code:
<Element>
<Select>
<Value>
:0
(G:Var1) ++ (&gt;G:Var1)
g0
</Value>
</Select>
</Element>
will never terminate and will hang FS; the only way to stop FS then is via the MS-Windows task manager.

Rob
 
Thanks to All, A lot of good stuff here that i will file away....

Back to one of my original questions about using <visible> for control of code execution... based on what those above have said...
I get now that <visible> only works on text/images and other visible type objects, and that you can use the same conditionals within scripts etc to control their execution... but what about large sections of code ?

What if you have a whole section of xml code (like say 500+ lines) that you want to turn on/off?

I don't want to tell on myself but back in the day my first experience with programming was writing machine code for 6502 processor and then on to using "basic". The use of Gotos or jumps to subroutines for flow control were quite common. and they worked as a way of controlling flow and turning things on/off in programs. Now obviously that was like prehistoric times and a lot has changed and evolved, but are those, or can those types of things still be done in XML?

For example I have a "base" set of functions for my HUD/panel that I want to work ALL the time in all aircraft, then say i have 6 or 7 complete additional features that I only want to work if in approach for landing, then other features that I only want to work under other conditions etc etc. I noticed above that Rob shows and example of a Goto loop used in a script.... is there a way to jumps or "Calls" when working with large blocks of XML code? Jumps or "Calls" using lables, like the equivalent of "Call X" ... "go execute section X of code then come back here" kind of subroutine? Or is XML pretty much a linear type of programming flow? If none of the above is doable in MS gauge XML how would one approach controlling execution of large pieces of code?

I guess I should add here....is my concern about "turning off" sections of code to make it more efficient unfounded in this day and age? ie with the speed of computers being what it is now is efficiency in this type of code writing overrated based on actual gains in real use ? Ie am i being overly concerned, should i just use <visible> to turn off what i do or do not want to "see" and then be aware that the other related stuff is still being executed but don't be concerned about it. ???

Joel
 
Last edited:
Or is XML pretty much a linear type of programming flow? If none of the above is doable in MS gauge XML how would one approach controlling execution of large pieces of code?
Yes, it's just sequential execution of all elements.
That's also why it's so easy to program in XML: the elements in a gauge are just executed one after the other in one schedule, without "interrupts" or other real-time effects.
So:
- Any Avar you read in one schedule of the whole gauge, will have the same value thoughout the whole schedule of the gauge.
- Any Lvar you reference in a gauge schedule, will retain it's value unless you change it yourself in a preceeding element.

This also means that if you issue a key-event in an element, the result (in an Avar) won't be visible untill the next schedule of the gauge.

As to controlling the execution of sections of code, other then the display (or not) of visual elements: you don't need a Visibility section.
Just use a boolean or numbered state Lvar with a large IF section; setting this to a certain state (bool, or numbered) is done in a preceeding Element (or in a next element, for execution in the next schedule of the gauge).
Example: Look at the Catapult gauge, where most of the elements code is "protected" by the numbererd state of the catapult function.

Testing for execution of the whole element using a condition and an IF section, does exactly the same as the Visibility section in an display element.

Rob
 
PS:
If you are used to "subroutines" like in C, Basic or even assembler language. I am for that programming era too ..LoL.
Very roughly said, you can mimick the same thing in an XML gauge using Macros, since you can pass parameters to the Macro (via the stack, or using @1 @2 etc in the Macro call which implicitely uses the stack too).
And read results from the Macro execution too; passed via the stack, set Lvars, or whatever.

Rob
 
Yes, it's just sequential execution of all elements.
So:
(1)- Any Avar you read in one schedule of the whole gauge, will have the same value thoughout the whole schedule of the gauge.
(2).....This also means that if you issue a key-event in an element, the result (in an Avar) won't be visible untill the next schedule of the gauge.
Rob

Rob, et al

So (1), does that means that the sim is updating it's internal numbers on the same cycle as the gauge? Ie if I read an A:var value for one use in line 10 and again in line 2010 for another use it's going to have the same value ?

and (2), Not sure if I'm getting this part right.... so are you saying if your using a key press or button/switch click to display an object or run a script, it takes 2 cycles to actually see the result? if so if your using press down for one function and release for another does it take 4 cycles? I'm confused.

Joel
 
PS:
If you are used to "subroutines" like in C, Basic or even assembler language. I am for that programming era too ..LoL.
Very roughly said, you can mimick the same thing in an XML gauge using Macros, since you can pass parameters to the Macro (via the stack, or using @1 @2 etc in the Macro call which implicitely uses the stack too).
And read results from the Macro execution too; passed via the stack, set Lvars, or whatever.

Rob
So can a macro contain a whole section of code (meaning tags and all)?

So using macros I can.
Code:
given L:var1=1, L:var2=2,L:var3=3

Macro Name="macro">(L:var3, number) + </Macro>

<Select>
<Value> (L:var1, number) (L:var2, number) + @macro + (&gt;L:var4, number) </Value>
</Select>

and end up with L:var4 =6 ?

Joel
 
XML scripting is very flexible, yet that very flexibility can also lead to utter confusion. For the sake of my sanity, I tend to use <Element> sections only for displaying stuff I need to see, and <MouseRect> for mouse actions.

All actual logic and calculations I group into a single <Update>* section. Knowing that execution of the script is top-down linear, it allows me to keep better track of my logic flow. I can therefore make intelligent use of 'go to' should it be necessary, or better still conditional events to control logic branches, including one to skip over entire sub-sections of script if desirable.

I'm also one of those ancient dinosaurs who still carefully plan my 'program logic' beforehand with the time-honored flowchart using actual paper and pencil. :rotfl:

Nota bene: Up until now I've stuck pretty much to using the FS9 XML Schema, avoiding the more verbose FSX XML Schema. Unfortunately, it appears that DTG's FSW has eliminated the FS9 XML Schema (presumably because of dropping GDI+), so if I ever do get into developing for FSW I will have to refactor a lot of my avionics work.
 
Not sure if I'm getting this part right.... so are you saying if your using a key press or button/switch click to display an object or run a script, it takes 2 cycles to actually see the result? if so if your using press down for one function and release for another does it take 4 cycles? I'm confused.

Events and Traps wiki
 
Back
Top