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

XML conditional macros

Messages
7
Country
us-texas
Is it possible in XML to have a conditional argument that selects one set of macros or another set of macros? Conceptually, here is what I want to do:

If argument is true

Macro1 = a
Macro2 = b
Macro3 = c

Else

Macro1 = x
Macro2 = y
Macro3 = z

I've searched in the forums for hours and experimented with a variety of approaches (if statements, L: variables, Visible commands, case arguments, etc.). I'm hoping that I'm simply using incorrect search keywords in my research or that I'm overlooking something that is very simple.

Is this idea possible in XML?
 
I'm hoping that I'm simply using incorrect search keywords in my research or that I'm overlooking something that is very simple.

Is this idea possible in XML?

Actually it depends on what you want to achieve.

The basic option would be:

Macro1 = conditional if{ a } els{ x }
Macro2 = conditional if{ b } els{ y }
Macro3 = conditional if{ c } els{ z }

Maybe if you expand a bit your intentions would be easier to understand the whole issue.

Tom
 
As Tom says, coding this within each macro is probably the most straightforward way to handle this.
 
Sorry to be slow to respond. My work day interferes with what I really want to be doing (FSX).

I would like to create a clickable spot that sets a local variable to select the text colors that will be displayed.

Code:
<!-- If ((L:ColorSelect,bool) 0 ==) then use these colors -->
<Macro Name="Color1">Yellow</Macro>
<Macro Name="Color2">Red</Macro>

<!-- If ((L:ColorSelect,bool) 1 ==) then use these colors -->
<Macro Name="Color1">Aqua</Macro>
<Macro Name="Color2">Blue</Macro>


<!-- In each <Element> use the selected color macros -->
<FormattedText X="12" Y="10" Font="MS Sans Serif" FontSize="10" Color="@Color1" BackgroundColor="@Color2" >


I would also like to use a macro to replace the entire <FormattedText> line because there are a lot of them in my gauge. But using quotation marks or &quot; causes the gauge to fail. I have not found any macro examples that include quotation marks so I suspect they are not allowed in macros.
 
If in doubt refer to the default GPS295 code. It has lots of examples on how to use various code.

This might work (although I have never personally passed a variable to a macro but the GPS FitToZoom macro is an example of one that does. Using the brackets after the @macro appears to set the value which is passed and @1 in the Macro definition reads the value. In this example I just store the value in the L var.

Code:
<Macro Name="macro1"> @1 (>L:storetheval,number)</Macro>

condition
if{
@macro1(a)
@macro2(b)
@macro3(c)
}
els{
@macro1(x)
@macro2(y)
@macro3(z)
}

Although I typed that all in before your latest reply so it probably doesn't apply to your particular situation.

It is important to remember that macros are not functions but simply text replacers.
So Color="@Color1" becomes Color="Yellow".

I wouldn't try to load up my code with macros personally as I suspect that it all gets replaced by the XML parser during runtime. I made a gauge with a huge macro and was calling it a few times in the gauge but it killed FSX.

You could give this a go but I can't guarantee it would work (can you have two macro name declarations?) EDIT: Tested this and no, it doesn't work.
Code:
(L:ColorSelect,bool) 0 ==
if{
<Macro Name="Color1">Yellow</Macro>
<Macro Name="Color2">Red</Macro>
}
els{
<Macro Name="Color1">Aqua</Macro>
<Macro Name="Color2">Blue</Macro>
}

<!-- In each <Element> use the selected color macros -->
<FormattedText X="12" Y="10" Font="MS Sans Serif" FontSize="10" Color="@Color1" BackgroundColor="@Color2" >
 
Last edited:
There is supposed to be something called gauge color scripts (in the SDK docs under creating XML gauges) but I've never managed to get these working nor have I ever seen an example of one working.

In theory, instead of using BackgroundColor and Color you would use BackgroundColorScript and ColorScript in your formattedtext lines.

Here is the text from the SDK about scripts:

Scripts can be used to evaluate a color. The same expression evaluation is used as for numerical values, but in this case the script must evaluate to a string containing either the name of the color, or the RGB hex value of the color. In this case strings must be enclosed in single quotes.

For example, the following scripts evaluate to red if the indicated airspeed is greater than 300 knots, otherwise to blue.
  • 'red' 'blue' (A:AIRSPEED INDICATED, knots) 300 > ?
  • '0x0000ff' '0xff0000' (A:AIRSPEED INDICATED, knots) 300 > ?
  • 0x0000ff 0xff0000 (A:AIRSPEED INDICATED, knots) 300 > ?
I assume you could use something like:
Color = " 'Aqua' 'Yellow' (L:Colorselect,bool) ? "

EDIT: Tested this and I still can't get colorscripts to work. No good.
 
Last edited:
I would like to create a clickable spot that sets a local variable to select the text colors that will be displayed.

That would be simple:

Code:
<Macro Name="Color1">%((L:ColorSelect,bool) ! if{ 'Yellow' } els{ 'Aqua' })</Macro>
<Macro Name="Color2">%((L:ColorSelect,bool) ! if{ 'Red' } els{ 'Blue' })</Macro>

<FormattedText X="12" Y="10" Font="MS Sans Serif" FontSize="10" Color="@Color1" BackgroundColor="@Color2" >


I would also like to use a macro to replace the entire <FormattedText> line because there are a lot of them in my gauge. But using quotation marks or &quot; causes the gauge to fail. I have not found any macro examples that include quotation marks so I suspect they are not allowed in macros.

I'm afraid that won't be possible. Macros can replace script text only, and besides quotation marks are not supported in scripts.

Tom
 
Tom's solution does work:

Code:
<Macro Name="Color1">%((L:ColorSelect,bool) ! if{ 'Yellow' } els{ 'Aqua' })</Macro>
<Macro Name="Color2">%((L:ColorSelect,bool) ! if{ 'Red' } els{ 'Blue' })</Macro>

<FormattedText X="12" Y="10" Font="MS Sans Serif" FontSize="10" Color="@Color1" BackgroundColor="@Color2" >

Just tested it.
 
Last edited:
Woohoo! Success!

Tom's solution worked. I tried the other solutions but they weren't successful.

To answer the question about two macros with the same name: it did not create an error, it simply used the macro that was last defined.

I appreciate all the attention for my question. I've spent an embarrassing amount of time trying to figure it out and it was answered here in no time at all.

Thank you!
 
To answer the question about two macros with the same name: it did not create an error, it simply used the macro that was last defined.

That's true. There is a lot of information in this forum related to macros posted by me and other people. I think it would be worth that you do an extended search; should make you save precious time trying to figure out what has been already tested and proved to work fine.

And if you would want to go further, just take a look at XMLVarsExample.xml that is included with XMLVars module, posted in the Resources pages:

http://www.fsdeveloper.com/forum/resources/xmlvars.122/

It contains a set of advanced macros: simple ones, nested ones, with one to many arguments, etc. that are a good representation on how to make proper use of them.

Tom
 
I scoured multiple forums for examples of conditional macros. I even scrolled through all of the message headers in the FSDeveloper gauge forum. I saw multiple references to XMLVars and skipped them because I was looking for conditional macros, not local variables. As per your suggestion I just now downloaded XMLVars. And, of course, the first item in your example file is a conditional macro. Typical!

Over the many years I've learned that when I'm completely stymied by something it is usually because I'm missing something that is right in front of me or is because I'm thinking that the solution is more complicated than it really is.

Again, thanks for the guidance. I can now remove the sign from my wall, the one that says, "Bang head here."

Rick
 
BTW - This effort is part of an exercise to update my TextInfo Gauge that is available at Simviation, AVSIM and FlightSim. With each release I get feedback from users and have been improving it. I'm approximately 90% done with a complete re-write that addresses sizing issues, adds many functions and includes a lot of additional XML tutorial info in the instruction doc.

One of the basic premises of the gauge is that it is a greatly enhanced substitute for Shift-Z. It is a text display with a transparent background. But the transparency is a double-edged sword - it reduces the intrusion of the readouts on the simulation screen and also does not provide a solid background to provide contrast for the text. Changing sim conditions result in many instances in which the text is very difficult to see (example, white text while flying through a cloud). There is no single color that is 100% satisfactory.

I implemented the conditional macros in the gauge and the results are terrific. I defined one dark color set and one light color set. Now I can drop out of a cloud into a dark green mountain valley and it only requires a single click to change the colors of the display.

I included background color definitions which have a default color of black (transparent). Users will be able to designate non-black background colors to display solid backgrounds for even more contrast with just a mouse click.

Using conditional macros allows me to put the colors at the top of the script in a format that users can easily understand and modify, without having to do a search-and-replace in a file that has more than 1,000 lines:

Code:
<!-- COLORS  (Note: Black color will be rendered as transparent) -->

     <!-- TOP BUTTONS                                                PRIMARY COLOR     SECONDARY COLOR    -->
     <Macro Name="ColorTopFont">%((L:COLOR_SELECT,bool) !     if{      'Silver'   } els{  'Silver' })</Macro>
     <Macro Name="ColorTopBkgrnd">%((L:COLOR_SELECT,bool) !   if{      'Maroon'   } els{  'Maroon' })</Macro>

     <!-- Main Section -->
     <Macro Name="ColorMain1">%((L:COLOR_SELECT,bool) !       if{      'Maroon'   } els{  'White'  })</Macro>
     <Macro Name="ColorMain1Bkgrnd">%((L:COLOR_SELECT,bool) ! if{      'Black'    } els{  'Black'  })</Macro>

     <!-- Throttle Percentage and Airspeed -->
     <Macro Name="ColorMain2">%((L:COLOR_SELECT,bool) !       if{      'DarkRed'  } els{  'White'  })</Macro>
     <Macro Name="ColorMain2Bkgrnd">%((L:COLOR_SELECT,bool) ! if{      'Black'    } els{  'Black'  })</Macro>

     <!-- Autopilot Section -->
     <Macro Name="ColorAutopilot">%((L:COLOR_SELECT,bool) !   if{      'Maroon'   } els{  'White'  })</Macro>
     <Macro Name="ColorAutopilotBkgrnd">%((L:COLOR_SELECT,bool) ! if{  'Black'    } els{  'Black'  })</Macro>

     <!-- Radio Section -->
     <Macro Name="ColorRadios">%((L:COLOR_SELECT,bool) !      if{      'Orange'   } els{  'Orange'  })</Macro>
     <Macro Name="ColorRadiosBkgrnd">%((L:COLOR_SELECT,bool) ! if{     '#202020'  } els{  '#202020' })</Macro>

     <!-- Flight Plan Section -->
     <Macro Name="ColorFlightPlan">%((L:COLOR_SELECT,bool) !  if{      'Maroon'   } els{  'White'   })</Macro>
     <Macro Name="ColorFlightPlanBkgrnd">%((L:COLOR_SELECT,bool) ! if{ 'Black'    } els{  'Black'   })</Macro>

     <!-- Other Controls Section -->
     <Macro Name="ColorOther">%((L:COLOR_SELECT,bool) ! if{            'Maroon'   } els{  'White'   })</Macro>
     <Macro Name="ColorOtherBkgrnd">%((L:COLOR_SELECT,bool) !  if{     'Black'    } els{  'Black'   })</Macro>

In the documentation I would like to mention my appreciation of the assistance of you folks. If you prefer that I not do that then please let me know.

Thanks!

Rick
 
Back
Top