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

FSX FSX Gauge XML: How to access dynamically LVARs

Messages
12
Country
india
I'm a noob to XML programming and have been trying to create a gauge for my A/C.

Please look at the code snippet( also attached as txt file).

Creating the variable(LVAR) name itself dynamically and accessing it seems impossible.

Is my requirement even possible?
(Background: Have written lots of code in LUA and badly need to pass strings (as ascii ) to LUA through these LVARS)


Thanks in advance

<?xml version="1.0" encoding="utf-8" ?>
<Gauge Name="test" Version="1.0">
<Macro Name="idd">@2 (>L:Test_@1,number)</Macro>

<Update Frequency="16">

<!-- Code works with static numbers-->
@idd(1, 400)
@idd(2, 500)
@idd(3, 600)

<!-- Code does not work with variables ( L1, L2, L3)-->
1 sp1
2 sp2
3 sp3

@idd(l1, 100)
@idd(l2, 200)
@idd(l3, 300)


</Update>
<Element >
<Position X="00" Y="0"/>
<FormattedText X="300" Y="900" Font="Arial" FontSize="24" LineSpacing="25" BackgroundColor="white" Color="blue" Bright="Yes" >
<String>
LVars value:\n
Test_1 value:
%((L:Test_1, number))%!d!\n
Test_2 value:
%((L:Test_2, number))%!d!\n
Test_3 value:
%((L:Test_3, number))%!d!\n

</String>
</FormattedText>
</Element>
</Gauge>
 

Attachments

  • testxml.txt
    825 bytes · Views: 236
Last edited:
Messages
1,564
Country
thailand
It looks as if you are trying to dynamically create an array of LVars that can be populated with variable numbers. Macros aren't the way to go to create the LVar names, but use of the XMLVAR class in Tom's XMLTOOLS can create an equivalent array.

XMLVARS are similar to L:Vars in that you can create a custom name for the variable and they can be read across the panel set. They are different (better) than L:Vars in that you can dynamically create array names as in the gauge below, and they can store strings as well as numbers. XMLTOOLS can be freely downloaded from the Resources section of this site.

Take a look at the attached gauge and see if it does what you want. It might meet your needs:

XML:
<Gauge Name="LVar Array Names" Version="1.0">
    <Size X="80" Y="170" />

    <Update>
        (L:InitSequence, bool) 0 ==
            if{
                <!-- Make XMLVAR array names -->       
                1 sp2
                :200
                    'Test_' l2 scat (>C:XMLVARS:StoreVarName, string)
                    l2 ++ s2
                l2 10 &lt;= if{ g200 }

                <!-- Write descending numbers into XMLVAR array variables -->               
                1 sp3
                :300
                    10 l3 1 - - 'Test_' l3 scat (>C:XMLVARS:SearchVarName, string) (>C:XMLVARS:NumberValue, number) 
                    l3 ++ s3
                l3 10 &lt;= if{ g300 }
                            
                1 (>L:InitSequence, bool)   
            }   
    </Update>

    <Element Name="BACKGROUND RECTANGLE"><Position X="0" Y="0"/><Rectangle Width="80" Height="170" FillColor="gainsboro" Bright="Yes"/></Element>

    <Element Name="WRITE XMLVARS">
        <Position X="5" Y="5"/>
        <FormattedText X="70" Y="160" Font="consolas" FontSize="8" LineSpacing="15" Color="#101010" BackgroundColor="gainsboro" Bright="Yes" >
            <String>
                %(1 sp4 10 sp5)
                %{loop}
                    %('Test_' l4 scat (>C:XMLVARS:SearchVarName, string) (C:XMLVARS:NumberValue, number))%!4d!
                    % :%('Test_' l4 scat)%!s!\n
                    %(l4 ++ s4 l5 &lt;=)
                %{next}
            </String>
        </FormattedText>
    </Element>
</Gauge>


which produces this:

1559021358838.png


Hope it helps,

Bob
 
Last edited:
Messages
12
Country
india
It looks as if you are trying to dynamically create an array of LVars that can be populated with variable numbers. Macros aren't the way to go to create the LVar names, but use of the XMLVAR class in Tom's XMLTOOLS can create an equivalent array.

XMLVARS are similar to L:Vars in that you can create a custom name for the variable and they can be read across the panel set. They are different (better) than L:Vars in that you can dynamically create array names as in the gauge below, and they can store strings as well as numbers. XMLTOOLS can be freely downloaded from the Resources section of this site.

Take a look at the attached gauge and see if it does what you want. It might meet your needs:

XML:
<Gauge Name="LVar Array Names" Version="1.0">
    <Size X="80" Y="170" />

    <Update>
        (L:InitSequence, bool) 0 ==
            if{
                <!-- Make XMLVAR array names -->      
                1 sp2
                :200
                    'Test_' l2 scat (>C:XMLVARS:StoreVarName, string)
                    l2 ++ s2
                l2 10 &lt;= if{ g200 }

                <!-- Write descending numbers into XMLVAR array variables -->              
                1 sp3
                :300
                    10 l3 1 - - 'Test_' l3 scat (>C:XMLVARS:SearchVarName, string) (>C:XMLVARS:NumberValue, number)
                    l3 ++ s3
                l3 10 &lt;= if{ g300 }
                           
                1 (>L:InitSequence, bool)  
            }  
    </Update>

    <Element Name="BACKGROUND RECTANGLE"><Position X="0" Y="0"/><Rectangle Width="80" Height="170" FillColor="gainsboro" Bright="Yes"/></Element>

    <Element Name="WRITE XMLVARS">
        <Position X="5" Y="5"/>
        <FormattedText X="70" Y="160" Font="consolas" FontSize="8" LineSpacing="15" Color="#101010" BackgroundColor="gainsboro" Bright="Yes" >
            <String>
                %(1 sp4 10 sp5)
                %{loop}
                    %('Test_' l4 scat (>C:XMLVARS:SearchVarName, string) (C:XMLVARS:NumberValue, number))%!4d!
                    % :%('Test_' l4 scat)%!s!\n
                    %(l4 ++ s4 l5 &lt;=)
                %{next}
            </String>
        </FormattedText>
    </Element>
</Gauge>


which produces this:

View attachment 49705

Hope it helps,

Bob
Thanks Bob. I will definitely look into it. But please tell me that the resultant LVARS can be accessed by LUA ( as said earlier I have lots of code in LUA(FSUIPC) that need to access these variables.

Thanks a ton
 
Messages
1,564
Country
thailand
But please tell me that the resultant LVARS can be accessed by LUA ( as said earlier I have lots of code in LUA(FSUIPC) that need to access these variables.
That's the part I was wondering about. I don't know.

I have a feeling that Tom would have mentioned use of XMLVARS in response to your question if the LUA connection could be made, so maybe the prognosis isn't great but I wouldn't know.

There have been a couple of recent threads involving LUA - FSUIP - XML that may shed some light on this .. dunno ... but worth a read through:

XML Gauge Limits in FSX

Triggering XML event with a hardware button instead of mouse

Tom Aguilo or Roman Stoviak, among others, may be able to expand on this.

Bob
 
Messages
12
Country
india
That's the part I was wondering about. I don't know.

I have a feeling that Tom would have mentioned use of XMLVARS in response to your question if the LUA connection could be made, so maybe the prognosis isn't great but I wouldn't know.

There have been a couple of recent threads involving LUA - FSUIP - XML that may shed some light on this .. dunno ... but worth a read through:

XML Gauge Limits in FSX

Triggering XML event with a hardware button instead of mouse

Tom Aguilo or Roman Stoviak, among others, may be able to expand on this.

Bob
Thanks Bob for taking time to read and reply. Appreciate it much. May be I should investigate writing the gauge in c++ so that i can use
execute_calculator_code which is similar to lua code ipc.writeLvar("LVarName", value)

Thanks again..
 

taguilo

Resource contributor
Messages
1,585
Country
argentina
But please tell me that the resultant LVARS can be accessed by LUA ( as said earlier I have lots of code in LUA(FSUIPC) that need to access these variables.

I really don't know, never tried. If LUA supports C: custom vars, then it would be possible to retrieve info from XMLVars.
You could try by extracting a C:fs9gps variable value. For example load a Flight Plan and try

val = varget("C:fs9gps:FlightPlanIsActiveFlightPlan","bool")

If returns 1 then it works.

May be I should investigate writing the gauge in c++ so that i can use
execute_calculator_code which is similar to lua code ipc.writeLvar("LVarName", value)

In c++ gauges there's no need for that. You can dynamically define an LVAR name and initialize it so it will be accesible by other XML/LUA/C++ gauge(s).

Tom
 
Messages
12
Country
india
Thanks everyone for helping out and providing continued inputs. Appreciate it. I will try out and post feedback on this very thread.
 
Messages
12
Country
india
I really don't know, never tried. If LUA supports C: custom vars, then it would be possible to retrieve info from XMLVars.
You could try by extracting a C:fs9gps variable value. For example load a Flight Plan and try

val = varget("C:fs9gps:FlightPlanIsActiveFlightPlan","bool")

If returns 1 then it works.



In c++ gauges there's no need for that. You can dynamically define an LVAR name and initialize it so it will be accesible by other XML/LUA/C++ gauge(s).

Tom
Tried accessing the GPS variable as suggested directly in Lua( FSUIPC) but lo the result was '0'. Thanks anyway:)

Now I will try using C++ to dynamically create LVARS. Will post back the result soon( I need to download community edition of visual studio and set it up..)
 
Messages
12
Country
india
Posting back the solution to read flight plan in XML and passing the same to LUA via a convoluted process...:) The reason being did NOT want to a) parse the flight plan b) pre-read bgl files or FSUIPC runways.xml and create/collect airport/runways information since whenever there is some change to runway information I was forced to do pre-processing. Even though this XML method is convoluted its very convenient...
 

Attachments

  • test_L.xml.txt
    21.1 KB · Views: 196
  • test.lua.txt
    3.2 KB · Views: 178
Top