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

External config file with XML

Messages
131
Country
unitedstates
I have search, and think I know the answer already, but is it possible to use an config file to define variables for use in an XML gauge?

I am working on a ASI that will have color bands, and V speed indicators. I have it working fine, but the speeds to define the values are all coded into the gauge. I would like to make it easier to move the gauge to different aircraft, without have to make a different version for each one.

My back up plan is to make a second gauge, that will be invisible on the panel, to define the variables. I am correct in thinking that gauges can share L vars right? This would allow easy changing of the values, and I could save different versions of the simpler XML.
 
Messages
1,243
Country
canada
Your most likely going to need to build a dll to read in the config info. This is just a guess on my part but I don't see any read file commands in the xml gauge SDK.
 

n4gix

Resource contributor
Messages
11,674
Country
unitedstates
XML Scripting has absolutely NO file I/O at all. Period.

Either stick with your 'invisible gauge' idea, or write a C gauge that will read an .ini file and pass the values to your XML gauge.
 

B21

Messages
149
Country
unitedkingdom
I think the 'invisible gauge' idea is pretty neat. Just writing the settings to L: variables amounts to a text config file you can drop into the same folder as the proper gauge. A lot easier to write and install than a C DLL, that's for sure.

If you're smart you'll be able to compress all the 'envelope' header and footer XML into one or two lines, so the file is mostly made up of 1-line-per-config-value.

There's a trick worth knowing that only writes the variables *once* rather than on every update cycle of the gauge. If it's of any value at all, here's the 'init' section of an XML gauge I'm writing:

Code:
<Element id="init">
            <Select>
                <Expression>
                    <Comment><Value>
                          This code runs *once* when the gauge is loaded because
                          the B21_C4_init bool gets set to true at the end of the init
                          routine so it doesn't run on subsequent updates
                          </Value>
                    </Comment>
                    <Script>
                          (L:B21_C4_init, bool) 0 == 
                          if{
                            1 (&gt;L:B21_C4_cursor, number) 
                            0 (&gt;L:B21_C4_needle, number)

                            ... ton of init code missed out
                            
                            1 (&gt;L:B21_C4_init, bool) 
                          }
                    </Script>
                </Expression>
            </Select>
        </Element>

I use the 'select' element as a convenient holder for general blocks of script, and I need a bit of a structure because the gauge (a gliding computer) is complex (3000 lines of code...). Maybe someone has a better idea.

Note with two gauges on a panel, you'd need the 'proper' gauge to only interpret the initialised variables *after* L:B21_C4_init (in my example) has become 'true' because you can't guarantee the 'init' gauge will complete it's cycle before the proper gauge executes an update cycle. Before that, the variables will be zero which might not be a problem so long as your code accepts that for a brief period.

B21
 
Last edited:
Messages
131
Country
unitedstates
I did indeed use an invisible gauge. I also make it trigger a bool to verify if has "initialized" at to make sure it only does it once. While on the subject, it is also important to make sure that the initialization occurs as soon as the sim is loaded, hence, the gauge should be put on the main panel, not a popup panel. I scratched my head for a while until I remembered gauges on popup panels don't load until the window is opened.

This is such a simple approach, I can't believe I haven't found it discussed before. This approach even allows you to keep an un-cabbed xml file in your panel folder, making it simple to use the gauge on multiple airplanes, and easy to change the values.
 
Messages
131
Country
unitedstates
Here is the code for the config gauge.
Code:
<?xml version="1.0" encoding="UTF-8"?>

<SimBase.Document
        Type="AceXML"
        version="1,0"
        id="Config">
    <Descr>AceXML Document</Descr>
    <Filename>Config.xml</Filename>
    <SimGauge.Gauge id="Config">
        <FloatPosition>0.000,0.000</FloatPosition>
        <Update id="Set V Speeds">
            <Script>(L:Initialized, bool) ! if{
163 (&gt;L:Vne, knots)	//Never exceed speed 
129 (&gt;L:Vno, knots)	//Maximum structural cruising speed 
85 (&gt;L:Vfe, knots)		//Maximum flap extended speed 
40 (&gt;L:Vso, knots)		//Stall speed or minimum flight speed in landing configuration 
48 (&gt;L:Vs, knots)		//Stall speed or minimum flight speed in normal configuration 
105 (&gt;L:Va, knots)		//Design maneuvering speed at max gross weight 
68 (&gt;L:Vbg, knots)		//Best glide speed 
65 (&gt;L:Vr, knots)		//Rotation Speed 
60 (&gt;L:Vref, knots)		//Landing reference speed 
62 (&gt;L:Vx, knots)		//Best angle of climb speed 
74 (&gt;L:Vy, knots)		//Best rate of climb speed 
0 (&gt;L:Vle, knots)		//Maximum landing gear extended speed 
0 (&gt;L:Vlo, knots)		//Maximum landing gear operating speed 
0 (&gt;L:Vmc, knots)		//Minimum control speed with critical engine inoperative 
0 (&gt;L:Vyse, knots)		//Best rate of climb speed with critical engine inoperative 
1(&gt;L:Initialized, bool) }</Script>
        </Update>
    </SimGauge.Gauge>
</SimBase.Document>

I don't know if the header could be stripped down, but it doesn't really matter. As you can see, the variable are easily identified, and changed
 

B21

Messages
149
Country
unitedkingdom
Neat.

FYI names like L:VX could easily be crapped on by another (someone else's) gauge and you'd take *forever* to diagnose that bug...

It'd be easy for you to global replace "L:" with "L: DNLK_" (space inserted just to avoid a frickin smiley)

B21
 
Last edited:
Messages
516
I put all gauges that have to run immediately upon flight load onto an invisible panel (i.e. no background and no bitmaps) and set the visible=1 in the panel.cfg.

This makes sure that the gauge loads irrespective of what view the user saved the flight in, includng external views. If you do all of your computational stuff in a gauge like that and only ever do display code on your visible panel gauges then you'll never encounter problems when gauges don't run until the user opens the panel.

Si
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
I put all gauges that have to run immediately upon flight load onto an invisible panel (i.e. no background and no bitmaps) and set the visible=1 in the panel.cfg.

This makes sure that the gauge loads irrespective of what view the user saved the flight in, includng external views. If you do all of your computational stuff in a gauge like that and only ever do display code on your visible panel gauges then you'll never encounter problems when gauges don't run until the user opens the panel.

Si

Code only gauges are very useful in XML panels, because they save the need to repeat complex code in many of them across the panelset.

In FSX, these ones should be placed always in VC01 section as the default loading mode is Virtual Cockpit. In this case, 2D panel gauges -including main- are not loaded until switching to 2D, no matter the visible=1 condition in panel.cfg. BUT the other way does apply: any flight saved in 2D panel mode (or with 2D panel by default) will load VC gauges as well-if there is a VC section-, so the advantage of placing these kind of gauges in VC main section.

If the XML gauge is a var init only, an <Update Frequency="1"> can be used to let it execute once a second only, thus saving processing time.

Tom
 
Messages
131
Country
unitedstates
...any flight saved in 2D panel mode (or with 2D panel by default) will load VC gauges as well-if there is a VC section-, so the advantage of placing these kind of gauges in VC main section.


So if I have FSX to default to the main 2d panel, never even opening the VC, does this still hold true?

Also...about update freq. 1 is the slowest, 0 seems to be the fastest, so numbers between 0 and 1 scale the freq? The reason I ask is I have read somewhere that the update freq is in Hz, meaning a higher number would be faster. Can you shed some light here. Also, is there a better way than using an update for var init?
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
So if I have FSX to default to the main 2d panel, never even opening the VC, does this still hold true?

That's correct.

Also...about update freq. 1 is the slowest, 0 seems to be the fastest, so numbers between 0 and 1 scale the freq? The reason I ask is I have read somewhere that the update freq is in Hz, meaning a higher number would be faster. Can you shed some light here. Also, is there a better way than using an update for var init?

Frequency number is the number of times per second that the gauge is refreshed. So 1 means once a second, 6 would be six times, up to 18 which is the standard rate (18 HZ). 0 (zero) is ignored -same as standard. So basically yes, a higher number is faster though I haven't found real difference when higher than 10.

Now, placing code in <Update> would be the best approach for processing that needs to be executed at standard rate (18 Hz) no matter the Frequency property. But if you want to limit the refresh rate of the <Element> set, you would use Frequency=n and put the var init within a script of a single element.

Just to remind, refresh rates:

<Update></Update> [always 18 hz (or less if FPS is low). Not afected by Frequency.

<Element></Element> by default (no Frequency) 18 hz, otherwise affected by Frequency in <Update>

Hope this makes sense to you.

Tom
 
Top