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

Macro Parameters

Messages
5
Country
us-michigan
I'm very new here, though I have found a lot of very useful content on this forum. Here's a situation I haven't found any information about, though.

I'm trying to develop a sound gauge using the dsd_fsx_xml_sound gauge that selects sounds using a macro within the XML file.

The macro looks like this:

<Macro>Name="CallSpeed">(>L:Call@1Kt,enum)</Macro>

I have a sound gauge ini file set up with the sound files as necessary, along with the LVar assignments to match.

LVar00=Call80Kt
LVar01=Call81Kt
. . .


When I send a literal value to the macro, like

<Update>
. . . . @CallSpeed(80)
</Update>

everything works fine, but if I try:

<Update>
. . . . @CallSpeed((A:Airspeed Indicated,knots) flr)
</Update>

I get no sound.

I have tried various forms of the Airspeed variable to get this to work, all for naught, so I have had to write an intermediate macro to translate the variable to a literal, resulting in a long macro that seems wasteful and hard to maintain:

<Macro Name="SelectAirspeed">
(A:Airspeed Indicated,knots) flr 80 == if{ @CallSpeed(80) }
(A:Airspeed Indicated,knots) flr 81 == if{ @CallSpeed(81) }
. . . etc.
</Macro>

And then:

<Update>
. . .
@SelectAirspeed
</Update>

This works fine, but the list of airspeeds, from 80 to 125 knots is large, and I intend to use the same concept for altitude callouts. . .

My question: How, if it is possible, can I use airspeed variable directly?

Thank You
Paul
 
XML is so much fun. . .I would love to know how the macro processes that kind of thing - it doesn't hang up, it appears to try to comply.

It's hard to think of a macro as merely script elements instead of methods within an object. . .And Microsoft believes in objects, too!

I only recently (while creating this gauge, in fact) found out that labels and the "quit" command are very bad ideas in a macro, too.

Oh, well, the long version works, and if so, I guess that's good enough.

Thanks for the quick reply, too.
 
My question: How, if it is possible, can I use airspeed variable directly?

Unfortunately it is not possible at all. Macros are nothing more than literal replacement of text, which is done when FS parses the XML file to translate it into runtime code.

XML is so much fun. . .I would love to know how the macro processes that kind of thing - it doesn't hang up, it appears to try to comply.

Parameters in a macro call are kinda pieces of script to be inserted in replace of the parameter id within the macro. You can think of them as macros within a macro.

By your example:

<Macro>Name="CallSpeed">(>L:Call@1Kt,enum)</Macro>

When you call the macro with this:

@CallSpeed(80)

FS translates it to

(>L:Call80Kt,enum)

which is a valid sentence

Now, if the macro is called like this:

@CallSpeed((A:Airspeed Indicated,knots) flr)

It is translated into:

(>L:Call(A:Airspeed Indicated,knots) flrKt,enum)

which is obviously a wrong sentence.

Oh, well, the long version works, and if so, I guess that's good enough.

There are other resources you can use, appart from macros, to shorten the code. Registers (s0...s49) are a very good option and these really save runtime resources; if you like XML scripts you'll like them the most.:)

Tom
 
I had already used a similar idea to set up thumb-wheel switches using this macro call:

@SetThumbWheels((A:Indicated Altitude, feet) (A:PLANE ALT ABOVE GROUND, feet) - 3000 + 500 / ceil 500 * ,Ft) (I know I could have used the terrain value for the first element of this, but I want to use the pilot's perspective - if the altimeter setting is incorrect, the calculated altitude could be incorrect as well.)

The SetThumbWheels macro correcly uses @1 as a value, @2 as an individual variable name to set five thumbwheels to their correct values, and made me believe that I could do a similar thing with the other one. Not possible, I guess, but that's okay.

I have given some thought to using the XMLVar dll to do this, but so far I haven't got a scheme to do it.

I'm not a big fan of XML; my previous comment was meant in a very, very tongue-in-cheek way. It seems very retro, worse syntax than any other programming language I have ever encountered. It took me hours to realize that "if{" and "els{" and "}" all need spaces before and after, and I only discovered that by accident. . .FS doesn't complain about it, of course, the gauge just doesn't work right. Talk about pulling hair out!

I'm still coming to grips with the fact that a multi-line macro isn't a procedure or method, just a bunch of text that the parser inserts wherever, thus making for lots of problems for me. It took me hours to discover that "quit" in the macro extended to the script surrounding it. . .and I still don't know how far into the following script it extends.

I'm a little slow sometimes, but eventually I can grasp the picture, I hope.

I think this forum has done the most for me in terms of finding out about those little quirks, as reading the SDK documentation was mostly worthless.

Paul
 
Last edited:
I have given some thought to using the XMLVar dll to do this, but so far I haven't got a scheme to do it.

Unfortunately XMLVars won't be useful here because Doug's gauge ini file uses LVars definitions.

I'm not a big fan of XML; my previous comment was meant in a very, very tongue-in-cheek way. It seems very retro, worse syntax than any other programming language I have ever encountered. It took me hours to realize that "if{" and "els{" and "}" all need spaces before and after, and I only discovered that by accident. . .FS doesn't complain about it, of course, the gauge just doesn't work right. Talk about pulling hair out!

Well, XML scripts are far away from being a programming language. However, they are a clever solution -if not the best- when dealing with interpreted-source code like XML files provide. After all, that is the way all kind of code is handled in the very low (assembler) level: pushing and poping values from a stack, jumps to labels, etc.

Tom
 
I think that it is unfortunate that MS/ACES named these things "Macros" since that implies functionality that simply does not exist at all.

On the other hand, I guess naming them for what they actually are would likely not be much of an improvement: @SubstituteScript... :rolleyes:

As for the "quit" tag, it's only useful if you have either an implicit loop or a 'goto' loop within a single element structure.
 
Last edited:
Well, I guess they used Macro as to give a similar concept to what #define means in C++, which is usually called a Macro as well.

As for the quit operator, actually can be very useful if properly placed in a long script.

For example, if there is such one like (pseudocode):

Code:
Something 
     if{  Do this [COLOR="Red"]quit[/COLOR] }
     els{   
              line 1
              line 2
              ...
              line 99
           }

That quit in the if{ evaluation will avoid all those 99 els{ lines from being read at runtime !

Tom
 
So does the quit command result in moving on out of this Update object without any further processing? Condition 3 and following would only be evaluated if Condition 1 was false?

<Update>
(L:Condition1,bool)
if{ (L:Condition 2,bool)
if{ (L:Variable1,enum) do something quit }
els{ L:Variable2, enum) do something else quit }
<!-- Actually, the quit could go here-->
}
(L:Condition3, bool)
if{ etc. etc. etc. }
script continues. . .
</Update>
 
That's correct, and maybe these examples help:

Code:
[SIZE="4"]<Update>
(L:Condition1,bool) 
if{ (L:Condition 2,bool)
if{ (L:Variable1,enum) do something [COLOR="Red"]quit[/COLOR][/SIZE][I] [SIZE="2"]} 
els{ L:Variable2, enum) do something else quit }
<!-- Actually, the quit could go here-->
}
(L:Condition3, bool)
if{ etc. etc. etc. }
script continues. . .[/SIZE][/I][SIZE="4"]
</Update>[/SIZE]

If Condition 2 is true, the complete code in small italics after the quit in red will be discarded for evaluation (not parsed at all) .

Code:
[SIZE="4"]<Update>
(L:Condition1,bool) 
if{ (L:Condition 2,bool)
if{ (L:Variable1,enum) do something quit } 
els{ L:Variable2, enum) do something else [COLOR="Red"]quit[/COLOR][/SIZE] [I] [SIZE="2"]}
<!-- Actually, the quit could go here-->
}
(L:Condition3, bool)
if{ etc. etc. etc. }
script continues. . .[/SIZE][/I][SIZE="4"]
</Update>[/SIZE]

And the same here if Condition 2 is false.

Tom
 
Last edited:
Well, that explains some issues I encountered in the past. I had a notion that the quit command would skip outside the braces and resume as soon as it could, not exit the whole script.

Thanks for the explanation.

I don't know how many times I've read the XML gauge creation part of the Panels SDK, all six pages of it, and given up in disgust - Their documentation is as sparse as XML itself. I'm sure there are many out there like me who have questions that for some reason haven't been answered, and this is great.
 
Back
Top