• 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 [Solved] Very weird macro behavior

Heretic

Resource contributor
Messages
6,830
Country
germany
I know XML scripts operate by the "garbage in, garbage out" principle, but I just can't find the garbage in this one.

Code:
<Macro Name="GenAmpLimit">300</Macro>
<Macro Name="LeftElecBusLoad">[bunch of code that is sound and results in 159]</Macro>
<Macro Name="RightElecBusLoad">[bunch of code that is sound and results in 157]</Macro>

<Element>
<Select>
<Value>
@GenAmpLimit @LeftElecBusLoad - (>L:000 Total Bus Load, Amps)
@GenAmpLimit @RightElecBusLoad - (>L:000 Total Bus Load2, Amps)
</Value>
</Select>
</Element>

What one would expect is a value of 300 - 159 = 141 for (L:000 Total Bus Load, Amps) and 300 - 157 = 143 for (L:000 Total Bus Load2, Amps).

What the code produces is a value of 141 for (L:000 Total Bus Load, Amps), but -457 for (L:000 Total Bus Load2, Amps).

If I replace the "@GenAmpLimit" in the evaluation with its value, i.e.
Code:
300 @LeftElecBusLoad - (>L:000 Total Bus Load, Amps)
300 @RightElecBusLoad - (>L:000 Total Bus Load2, Amps)
I get the same result. 141 and -457.

If I only query the macros, i.e.
Code:
@LeftElecBusLoad (>L:000 Total Bus Load, Amps)
@RightElecBusLoad (>L:000 Total Bus Load2, Amps)
the variables display the correct values, i.e. 159 and 157.


What the heck is going on here? :confused:




- Edit:

Even this won't work properly!

Code:
@GenAmpLimit (>G:Var8)
(G:Var8) @LeftElecBusLoad - (>L:000 Total Bus Load, Amps)
(G:Var8) @RightElecBusLoad - (>L:000 Total Bus Load2, Amps)

Or this!

Code:
<Macro Name="GenAmpLimit">300</Macro>
<Macro Name="LeftElecBusLoad">[bunch of code that is sound and results in 159]</Macro>
<Macro Name="RightElecBusLoad">[bunch of code that is sound and results in 157]</Macro>
<Macro Name="LeftElecChrgBusLoad">@GenAmpLimit @LeftElecBusLoad -</Macro>
<Macro Name="RightElecChrgBusLoad">@GenAmpLimit @RightElecBusLoad -</Macro>

<Element>
<Select>
<Value>
@LeftElecChrgBusLoad (>L:000 Total Bus Load, Amps)
@RightElecChrgBusLoad (>L:000 Total Bus Load2, Amps)
</Value>
</Select>
</Element>

Time for one to fourhundred drinks.
 
Last edited:
What happens if you evaluate RightElecChrgBusLoad before LeftElecChrgBusLoad?
 
What happens if you evaluate RightElecChrgBusLoad before LeftElecChrgBusLoad?

Nothing in terms of results. The first macro in the list always returns a sensible value and the second one is always being screwed up after being subtracted from GenAmpLimit.
 
Maybe this:
Code:
@GenAmpLimit @LeftElecBusLoad - (>L:000 Total Bus Load, Amps)
@GenAmpLimit abs (>G:Var8) 
(G:Var8) @RightElecBusLoad - (>L:000 Total Bus Load2, Amps)
You shouldn't have to do this of course, but it might keep your rum costs down.
 
Well, I had to go the long way round and offload the BusLoad macros into a regular element/update blocks and save the result to L: vars. And that works as it's supposed to.

Still would like to know why the macros screwed up. Maybe Tom A. has an explanation.
 
I cannot tell unless I have the entire macro contents.
Are those macros huge?

Tom
 
With the entire macro sections:
Code:
<Macro Name="GenAmpLimit">300</Macro>
<Macro Name="LeftElecBusLoad">
(L:MM3_ELEC_LEB_SW, Bool) if{ (L:MM3_LEB_Total_Load, Amps) } (L:MM3_ELEC_REB_SW, Bool) ! if{ (L:MM3_REB_Total_Load, Amps) + } (L:MM3_ELEC_NEB_SW, Bool) ! if{ (L:MM3_NEB_Total_Load, Amps) + }
(A:ELECTRICAL GENALT BUS VOLTAGE:1, volts) 0 == (A:ELECTRICAL GENALT BUS VOLTAGE:2, volts) 0 &gt; and if{ (L:MM3_SB_Total_Load, Amps) + }
(A:ELECTRICAL GENALT BUS VOLTAGE:1, volts) 0 == (A:ELECTRICAL GENALT BUS VOLTAGE:2, volts) 0 == and
(A:ELECTRICAL GENALT BUS VOLTAGE:1, volts) 0 &gt; (A:ELECTRICAL GENALT BUS VOLTAGE:2, volts) 0 &gt; and or if{ (L:MM3_SB_Total_Load, Amps) 0.5 * + }
</Macro>
<Macro Name="RightElecBusLoad">
(L:MM3_ELEC_LEB_SW, Bool) ! if{ (L:MM3_LEB_Total_Load, Amps) } (L:MM3_ELEC_REB_SW, Bool) if{ (L:MM3_REB_Total_Load, Amps) + } (L:MM3_ELEC_NEB_SW, Bool) if{ (L:MM3_NEB_Total_Load, Amps) + }
(A:ELECTRICAL GENALT BUS VOLTAGE:1, volts) 0 &gt; (A:ELECTRICAL GENALT BUS VOLTAGE:2, volts) 1 &lt; and if{ (L:MM3_SB_Total_Load, Amps) + }
(A:ELECTRICAL GENALT BUS VOLTAGE:1, volts) 0 == (A:ELECTRICAL GENALT BUS VOLTAGE:2, volts) 0 == and
(A:ELECTRICAL GENALT BUS VOLTAGE:1, volts) 0 &gt; (A:ELECTRICAL GENALT BUS VOLTAGE:2, volts) 0 &gt; and or if{ (L:MM3_SB_Total_Load, Amps) 0.5 * + }
</Macro>

<Element>
<Select>
<Value>
@GenAmpLimit @LeftElecBusLoad - (>L:000 Total Bus Load, Amps)
@GenAmpLimit @RightElecBusLoad - (>L:000 Total Bus Load2, Amps)
</Value>
</Select>
</Element>
 
Try adding "els" after the first "if" in both macros:

Code:
<Macro Name="LeftElecBusLoad">
(L:MM3_ELEC_LEB_SW, Bool) if{ (L:MM3_LEB_Total_Load, Amps) } els{ 0 } (L: ...

Code:
<Macro Name="LeftElecBusLoad">
(L:MM3_ELEC_LEB_SW, Bool) if{ (L:MM3_LEB_Total_Load, Amps) } els{ 0 } (L: ...
 
Bjoern,

It is a logical issue between both macros. I did a quick check and in one case second macro does not put any value in the stack, else -300 is asigned to the variable.
In another situation 300 is added to one of the values in the stack. It's as much far as I can go as I don't know actual values for the variables involved.

Tom
 
Another possibility is that FS is confusing the macros because the first 8 characters are identical. Try rearranging the names so they are different from the start.

LeftElecBusLoad
RightElecBusLoad
ChgLeftElecBusLoad
ChgRightElecBusLoad
 
Ding! Ding! Ding! Luka and Tom had the right idea!

Adding an "els{ 0 }" to the first evaluation in the second macro produces the correct value for "(L:000 Total Bus Load2, Amps)".

Lesson learned: Always make sure that an evaluation in a macro at least returns zero as a value.


Thanks for the input, everybody!
 
Back
Top