• 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 XML Coding Question

Messages
159
Country
us-colorado
I am trying to write a small Lua script that will allow keystrokes to replace mouse clicks to switch a panel clock between 'Clock' mode and 'Timer' mode. Here is a small section of the original XML code:
Code:
Mode selector(%((L:ClockLc2Mode,bool))%{if}Timer%{else}Clock%{end})
(M:Event) 'LeftSingle' scmp 0 == if{(L:ClockLc2Mode,bool ) ! (>L:ClockLc2Mode,bool)
    1 (>L:ClockLc2MiddleSwitch,bool) }
(M:Event) 'LeftRelease' scmp 0 == if{ 0 (>L:ClockLc2MiddleSwitch,bool) }

The first code line above ends up as a tool tip displaying either Mode Selector(Clock) or Mode Selector(Timer) depending on the value of Lvar L:ClockLc2Mode. The problem is that my Lua script can't access L:ClockLc2Mode until the tool tip is made to appear by hovering the mouse over the clock Mode button. Any attempt to write or read L:ClockLc2Mode to determine what mode the clock is currently in returns a nil value until the tool tip has been displayed (I thought Lvars where initialized to 0 by the sim). So what I don't understand is how the first line of code is involved with making L:ClockLc2Mode accessible. I can't find the tool tip code in any of the XML files so I assume it is tucked away in one of the dlls or the model file.

Thanks for any ideas.
Al
 
Last edited:
From what I gather L:ClockLc2Mode can be initialized by both activating the tooltip OR clicking on the mode button. They are both user events with the mouse so may be hidden from the gauge loading initialization. Maybe adding this in any gauge or it's own gauge itself will initialize it for.lua use.

Code:
<Update>
(L:ClockLc2Mode, bool) sp0
</Update>
 
probably makes no diff but you might try adjusting the spaces:

if{(L:ClockLc2Mode,bool ) ... > if{ (L:ClockLc2Mode,bool) ...
 
Roman,

Why the sp0?

Bob

It could be anything, just something to read the L:Var outside of a mouse triggered event.
The hypothesis is that the var isn't initialized for lua use because it is only inside of a mouse triggered event.
Even something like -
Code:
<Update>
(L:ClockLc2Mode, bool) if{ quit } els{ quit }
</Update>
 
Last edited:
I found an existing Update section in one of the XML files and simply added in the line

(L:ClockLc2Mode, bool)

Works just fine.

Thanks all for the inputs, and for teaching me something about accessing Lvars inside and outside of a mouse triggered event.

Al
 
I have no gauge experience at all so would like to ask a few more questions. I'm trying to understand the big picture of how things fit together in this case.

Instead of adding the above line (L:ClockLc2Mode, bool) to an existing Update section, as a learning expereince I want to try and create a separate update file as suggested above, but am not sure what the 'header' info should be. Would something like the below be correct?

If so, I assume I would then add the file clock_mode.xml to the aircraft panel folder. Do I then also need to make a gauge entry in the panel.cfg file?

Besides the learning experience, if possible I'd like to find an update solution that does not require modifying existing files but rather just adding an additional file. That way if down the road the a/c is updated I do not have to add the changes back into the updated a/c files.

Thanks,
Al

Code:
<Gauge Name="clock_mode" Version="1.0">
   <Update>
      (L:ClockLc2Mode, bool)       <!-- or maybe (L:ClockLc2Mode, bool)  0  +  (> L:ClockLc2Mode, bool) -->
   </Update>
</Gauge>
 
I will typically create a single "gauge" script and name it "ProjectName_Logic.xml". This script is usually nothing more than one <Update> section into which I place all the gauge system's logic.

For example, the C310_Logic.xml script:
Code:
<Gauge Name="C310_Logic" Version="1.0">
    <Image Name="GTX 330_rect.bmp" ImageSizes="500,128" />
    <Element>
        <Position X="0" Y="0"/>
        <Select>
            <Value>
                <!-- Flip Magnetos if Engines are Running when loaded  -->
        (L:FirstLoad,bool) !
        if{
        1 (>L:C310_Pilot,bool)
        (A:GENERAL ENG COMBUSTION:1,bool)
        if{ 1 (>L:LeftMag_Left, number)
        1 (>L:LeftMag_Right, number)
        0 (>L:C310_Pilot,bool)
        1 (>L:C310_Chocks,bool)
        1 (>L:C310_Covers,bool)
        }
        (A:GENERAL ENG COMBUSTION:2,bool)
        if{ 1 (>L:RightMag_Left, number)
        1 (>L:RightMag_Right, number)
        0 (>L:C310_Pilot,bool)
        1 (>L:C310_Chocks,bool)
        1 (>L:C310_Covers,bool)
        }
        (A:CIRCUIT AVIONICS ON,bool) if{ 0 (>L:Avionics_On_Init,enum) }
        (A:ANTISKID BRAKES ACTIVE,bool) 0 == if{ (>K:ANTISKID_BRAKES_TOGGLE) }
        (A:LIGHT LANDING,bool) if{ 2 (>L:SwitchLL,enum) }
        16383 (>K:COWLFLAP1_SET)
        16383 (>K:COWLFLAP1_SET)
        1 (>L:FirstLoad,bool)
        }
      </Value>
        </Select>
    </Element>

  <Update Frequency="1">
    (A:GENERAL ENG PROPELLER LEVER POSITION:1,percent) 0 > (L:Prop1_Feathered,bool) and if{ 0 (>L:Prop1_Feathered,bool) }
    (A:GENERAL ENG PROPELLER LEVER POSITION:2,percent) 0 > (L:Prop2_Feathered,bool) and if{ 0 (>L:Prop2_Feathered,bool) }

    (L:LeftMag_Left, number) ! (L:LeftMag_Right, number) !  and   if{ (>K:MAGNETO1_OFF) }
    (L:LeftMag_Left, number)   (L:LeftMag_Right, number) !  and   if{ (>K:MAGNETO1_LEFT) }
    (L:LeftMag_Left, number) ! (L:LeftMag_Right, number)    and   if{ (>K:MAGNETO1_RIGHT) }
    (A:RECIP ENG LEFT MAGNETO:1,bool) ! (L:LeftMag_Left, number)  (L:LeftMag_Right, number) and and if{ (>K:MAGNETO1_BOTH) }

    (L:RightMag_Left, number) ! (L:RightMag_Right, number) !  and   if{ (>K:MAGNETO2_OFF) }
    (L:RightMag_Left, number)   (L:RightMag_Right, number) !  and   if{ (>K:MAGNETO2_LEFT) }
    (L:RightMag_Left, number) ! (L:RightMag_Right, number)    and   if{ (>K:MAGNETO2_RIGHT) }
    (A:RECIP ENG LEFT MAGNETO:2,bool) ! (L:RightMag_Left, number)   (L:RightMag_Right, number) and and if{ (>K:MAGNETO2_BOTH) }

    (A:ELECTRICAL MASTER BATTERY,bool)
    if{
    (L:MB_On_Init,enum) 0 == if{ 1 (>L:XMLSND10,bool) 1 (>L:MB_On_Init,enum) }
    (L:MB_On_Init,enum) 1 == if{ 2 (>L:XMLSND11,bool) }
    }
    (A:ELECTRICAL MASTER BATTERY,bool) ! (L:MB_On_Init,enum) 1 == and
    if{ 3 (>L:XMLSND11,bool) 1 (>L:XMLSND12,bool) 0 (>L:MB_On_Init,enum) }

    (A:ELECTRICAL AVIONICS BUS VOLTAGE,volts) 0 > (A:ELECTRICAL MASTER BATTERY,bool) and
    if{
    (L:Avionics_On_Init,enum) 0 == if{ 1 (>L:XMLSND13,bool) 1 (>L:Avionics_On_Init,enum) }
    (L:Avionics_On_Init,enum) 1 == if{ 2 (>L:XMLSND14,bool) }
    }
    (A:ELECTRICAL AVIONICS BUS VOLTAGE,volts) 0 ==
    (A:ELECTRICAL MASTER BATTERY,bool) !
    or
    (L:Avionics_On_Init,enum) 1 == and
    if{ 3 (>L:XMLSND14,bool) 1 (>L:XMLSND15,bool) 0 (>L:Avionics_On_Init,enum) }

    (L:Primer,enum) ! (A:ELECTRICAL MASTER BATTERY,bool) and if{  2 (>L:XMLSND16,bool) } els{  3 (>L:XMLSND16,bool) }

    (A:ELECTRICAL MASTER BATTERY,bool) (L:DoorSeal, number) 0 == and
    if{
    (P:Absolute time,seconds) 30 % 1 > !
    if{ 1 (>L:XMLSND18,bool) }
    }
  </Update>
  <Macro Name="AP_Click">
    1 (&gt;L:XMLSND2,enum)
  </Macro>
  <Keys>
    <On Event="AP_MASTER">@AP_Click</On>
  </Keys>
</Gauge>
 
I found an existing Update section in one of the XML files and simply added in the line

(L:ClockLc2Mode, bool)
Just for general information, the reason this is required is that the variable does not exist until it is first invoked. If that takes place in a "mouse click" then the results will be as you've already found.

By simply declaring it in an <Update> section, you are creating it, and initializing it to zero value (0) in one step!
 
Just for general information, the reason this is required is that the variable does not exist until it is first invoked. If that takes place in a "mouse click" then the results will be as you've already found.

By simply declaring it in an <Update> section, you are creating it, and initializing it to zero value (0) in one step!

Yes, an important point that I now understand!

So if I create a small update 'gauge' script just for the purpose of creating (invoking) some variables so they are accessible, how do I get the gauge script to be automatically run when the a/c is loaded?

Thx,
Al
 
Last edited:
You place that gauge into a VCockpit section in the plane's panel.cfg file. Gauges in such sections are always loaded, no matter the view mode or panels visible.

I know of one exception to this rule, and that is any On Event or On Key commands will only be active when that panel or VC is actually visible on the screen, in Cockpit view.

Hope this helps,
 
You place that gauge into a VCockpit section in the plane's panel.cfg file. Gauges in such sections are always loaded, no matter the view mode or panels visible.

I know of one exception to this rule, and that is any On Event or On Key commands will only be active when that panel or VC is actually visible on the screen, in Cockpit view.

Hope this helps,
That certainly does help, thanks Tom.
Al
 
Of course for your gauge entry you want to place the "gauge" in the upper left corner and minimized:

gauge00=logic!logic, 0,0,1,1
 
Of course for your gauge entry you want to place the "gauge" in the upper left corner and minimized:

gauge00=logic!logic, 0,0,1,1

Well, I used gauge00=logic!logic, 0,0 and it seemed to work ok. So does the absence of size parameters perhaps default to 1,1 (or can you use 0,0 for the size)? With a gauge that has no physical presence, are any location and size parameters really needed?

Thanks much for the continued help,
Al
 
I have a number of "invisible" gauges on the VC10 2D panel. From a function point of view their dimensions or positions don't seem to matter. But for clarity I keep them mostly separate. You do need to define the dimension and placings in the panel.cfg file though.
imvis.jpg


Code:
gauge121=DSD\DSD_fuel_dump!fuel_dump_transparent,  1,263,55,50,./Gauges/SUFLD.ini
gauge122=DM_VC10!NW_PROCESS,  -1,104,78,89
 
I assume that when no size values are given, FS defaults to the actual size of the background bitmap, which in this case is 0,0.
 
Hello. I came across this because things were working well when I last left the FS but today, the XML is not seeing the lua's LVars. I'll find out why but to answer ark1320's original question; why not use <Keys> <On key="n"/> rest of code </On> </Keys>? For example:

Code:
<Keys>
<On Key="323">(A:Autopilot Master,bool) 1 == (L:HDGtoGOtoBL, Degrees) 30 &gt;= and if{ (G:Var1) 1 &lt; if{ 0 (>G:Var1) } els{ (G:Var1) 1 - (>G:var1) } } </On>
<!-- v=86,[sh]v=256+86  -->
<On Key="342">(A:Autopilot Master,bool) 1 == (L:HDGtoGOtoBL, Degrees) 30 &gt;= and if{ (G:Var1) 5 &gt; if{ 6 (>G:Var1) } els{ (G:Var1) 1 + (>G:var1) } } </On>
</Keys>

I'm using G:Var, but I have used Key events (>K:...) and Lvars (>L:...) as well. In the above code, I am using [SH] C and [SH] V. For characters without using any [SH], or [CTRL] or [SH][CTRL], etc., On Key = "V" works as well. V = 86 , 86 is the ASCII equivalent to V. Google ASCII table to see other characters cross-referenced. Then with FSUIPC, I assign buttons to the keys and no more mouse inputs are required - nor keyboard... just a thought. I have to use FSUIPC because, unless someone out there knows differently, XML gauges don't access joystick buttons directly. If there is a direct way, please share.
 
unless someone out there knows differently, XML gauges don't access joystick buttons directly. If there is a direct way, please share.


Yeah, they can. You can trap a joystick button event and then run XML code just the same as trapping keyboard input.

Download an event logging application such as Tom Aguilo's XMLTOOLS or Doug Dawson's event_logger.

The screenshot below shows the display of the XMLEventsLogger.xml utility gauge from XMLTOOLS. I pressed the "7" button on my joystick and XMLEventsLogger returned EVENT ID: 10462. It is a hex number.

1559621921955.jpeg


Use that number, written in hex format, in your <On Event> trap:

XML:
<Keys>
  <On Event="0x10462">
    XML script to do something when my joystick "7" button is pushed
  </On>
</Keys>


Alternatively, you can use the decimal equivalent of 0x10462, which is 66658:

XML:
<Keys>
  <On Event="66658">
    XML script to do something when my joystick "7" button is pushed
  </On>
</Keys>


If you are familiar with FSUIPC, the control numbers listed in the documentation are shown in decimal format.

Bob
 
Last edited:
Hello. Thank you rpmc for that information. For FS2004, I used Doug Dowson's event logger, and the "Key_Events_Sent.log showed, in part:
By the way, unless I'm missing something, I could not see any button id's until I assigned a button to an FS event. When I assigned button 1 to adf, then I could see the id.

Time=321.927933; id=227; event_in=KEY_AXIS_AILERONS_SET; evdata=-844
Time=321.928003; id=30; event_in=KEY_ADF; evdata=0
Time=321.928016; id=978; event_in=KEY_ATC_MENU_CLOSE; evdata=0
So I tried this:

<Keys>
<On Event="0x30"> (>K:PAUSE_TOGGLE)
</On>
</Keys>

As a test, I added the above to an XML gauge but it did not work. So I tried using FSX using XMLTools and it showed the event was 10019. So I tried this in an FSX XML gauge but no go, and 10019 did not work in the FS2004 XML gauge either. So... 1) Why do the event id's for the same button not match? 2) Why did the XML code using the On Event to "pause" not work?
 
Back
Top