• 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 Macro question

Messages
137
Country
us-southcarolina
I ran across the following macro in a code segment that I'm using. The code segment works but i have no idea why and that's what's bothering me...I can't learn unless I understand why something does work as well as doesn't....

Code:
<Macro Name="mod">@1 @2 @1  @2 / flr * -</Macro>

This has left me confused. I assume that "@1" and "@2" are either calls to macro @1 and @2, or the definition of params to be used with the "mod" Macro ? I can find no reference or declaration of "@1" or @2 as a macro anyplace in the file I'm using so I leaning toward the later but I don't see anything in the SDK or the wiki here about this kind of thing when using macros( I might not be searching the wiki right). If I can get a brief explanation of the above and a link to any detailed info on using macros that would be great.

thanks

Joel
 
Last edited:
I did find some examples that confirm that @1 and @2 are params to be used in "@mod" macro. Now i need to understand why they are listed twice and how / flr * is applied to them both or just @2 ?

thanks
Joel
 
You are correct that @1 and @2 are parameters, or arguments passed to the mod macro. To understand the macro, you might want to look at the Stack wiki and then substitute your macro for the examples in the wiki. Your macro contains 4 operands (@1, @2, @1, and @2) and 4 operators (/, flr, *, and -).

upload_2017-5-10_12-9-33.jpeg

So, in this example, the mod macro yields the value 50.

Hope this helps.

Bob
 
Last edited:
So in effect all the Params (arguments) are pushed on the stack in the order listed and then the operands are applied as they are popped. Thanks
That explains a lot.

Just to make sure I understand, in the case of operators where the order make a difference (ex "-" or "/" ), the first off the stack, or the current result, is always second after the operator, as in your example, the first off is the "divisor" , and current result is subtracted from the next item off the stack. yes?

So using the macro example. When you call that marco do you just have to list the 2 different arguments or do you have to list them like the macro is defined as in

@mod(250, 100)
or
@mod(250, 100, 250, 100)

?

thanks so much for you help
Joel
 
Last edited:
The number of operands used by an operator depends on the operator. Most use two stack values (stack 0 and stack 1). Some operators use one (like flr), some use three. The divide operator requires two values. In the example, 250 (stack 1) and 100 (stack 0) are used. The calculation is stack 1 divided by stack 0 which yields 2.5. The two stack values required by the divide operator are popped off of the stack and replaced by the result, 2.5. The resulting stack is then 2.5, 100, 250.
 
Last edited:
So using the macro example. When you call that marco do you just have to list the 2 different arguments or do you have to list them like the macro is defined as in

@mod(250, 100)
or
@mod(250, 100, 250, 100)

?

thanks so much for you help
Joel
@mod(250,100)
 
Hi,

If your macro call was this:

@mod(250, 100, 250, 100)

Then the second 250 would be the value for @3 in the macro and your second 100 would be the value for @4. But since your macro doesn't define those, they would either be ignored or trigger an error (don't know which).
 
Thanks to all. With that problem solved moving on.

thanks to all. I'm so glad that you guys are out there and are willing to help. The longer I work with FS9/FSX the more i realize that so much of the how's/Why's etc lack detailed readily available documentation. You guys are the brain trust. I'd be DOA with out this forum.

Thanks
Joel
 
Then the second 250 would be the value for @3 in the macro and your second 100 would be the value for @4. But since your macro doesn't define those, they would either be ignored or trigger an error (don't know which).

They are simply ignored.

Besides, XML running scripts do not throw errors of any kind. They work as expected or they don't.

Tom
 
Hi Joel,

If it helps in future:
You can even use formula's in the macro call.
So (not a very usefull example, just to explain it):

Code:
@mod(250,100)

would have the same result of the Macro code as

50 (>G:Var1)
@mod((G:Var1) 200 +,100)

Rob
 
There is a little utility called Infix2Postfix in the SDK in folder

Environment Kit\Modeling SDK\bin\

also an InfixHelpFile.txt, same location.

Running your example gets you:

infix2postfix.jpg
 
Back
Top