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

Looping through variable indexes

tgibson

Resource contributor
Messages
11,875
Country
us-california
Hi,

I'm looking for a method to loop through variable indexes (FS9). Here is the current code I'm using, which stops at station load 10:

Code:
<Macro Name="StaLoad"> (G:Var8)
            s0 1 == if{ (A:Payload Station Weight:1, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 2 == if{ (A:Payload Station Weight:2, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 3 == if{ (A:Payload Station Weight:3, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 4 == if{ (A:Payload Station Weight:4, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 5 == if{ (A:Payload Station Weight:5, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 6 == if{ (A:Payload Station Weight:6, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 7 == if{ (A:Payload Station Weight:7, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 8 == if{ (A:Payload Station Weight:8, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 9 == if{ (A:Payload Station Weight:9, pounds) (L:Payload, number) + (&gt;L:Payload, number) } els{
            l0 10 == if{ (A:Payload Station Weight:10, pounds) (L:Payload, number) + (&gt;L:Payload, number) } 
             } } } } } } } } } 
		<!-- add station loads: max = 10 -->
	</Macro>

G:Var8 is incremented by a loop, and the code above totals up the Station Loads. But what I would really prefer is to say "loop through the station loads until you reach one that is 0, then stop". I tried to put a variable into an incrementing loop and pass that to the macro each time as the index value, but I could never get that to work. I also tried using the PAYLOAD STATION COUNT variable but it always returned 0 in my hands. Does anyone have any clues? Was I just doing something wrong?

Thanks,
 
PAYLOAD STATION COUNT variable but it always returned 0

Hi Tom,

(A:PAYLOAD STATION COUNT, number) is zero? That A:Var works for me (FS9).

I also have tried passing a variable as the index number without success. I really wish I knew of a way to do that.

Have you considered including "quit"? Will something like

d (&gt;L:Payload, number) 0 == if{ quit } els{ ......

work?

Bob
 
Thanks, knowing that the COUNT variable does work means I can work on it further. Too bad about not being able to use a variable for the index value...

Bill, it is a "Flight Engineer's Notepad" gauge, one page of which is a fuel planner. I need to total up the current payload so I can display how much fuel they can load and stay under MTOW, MLW, and ZFW.

Thanks,
 
Tom,

Why not just go with this:
Code:
(G:Var8) 0 ==
if{
(A:Payload Station Weight:1, pounds)
(A:Payload Station Weight:2, pounds) +
(A:Payload Station Weight:3, pounds) +
(A:Payload Station Weight:4, pounds) +
(A:Payload Station Weight:5, pounds) +
(A:Payload Station Weight:6, pounds) +
(A:Payload Station Weight:7, pounds) +
(A:Payload Station Weight:8, pounds) +
(A:Payload Station Weight:9, pounds) +
(A:Payload Station Weight:10, pounds) + (>L:Payload, number)
1 (>G:Var8)
}

If the user enters the menu system, I believe the GVar will reset, so you will trap payload changes.
Also, I wouldn't be afraid to just let the payload calculate each update.
Yes, it is wasteful, but doing arithmetic with A:Vars and L:Vars is pretty inexpensive - I don't think you would ever notice a performance hit.

Doug
 
Hi,

This is a very complicated gauge, and I just thought I would try to make it as efficient as possible. :)

But you are right, in this particular case it probably doesn't matter, since there are no K: variables involved.

Thanks,
 
Back
Top