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

FSXA G:Vars AGAIN for FSX this time!

Messages
160
Developed some XML for a mates AI Aircraft for FS9 using G:Vars, works a treat.

The same XML properly formatted for FSX produces nothing!

For eg
<code>
(G:Var1) 0 == if{ etc etc if{ etc etc } els{ etc etc } }
(G:Var1) 1 == if{ etc etc if{ etc etc } els{ etc if{ etc } els{ etc } } }
</code>

Did it this way to be able to have complex if / els after the initial G:Var comparison. Also makes it easier to read/debug at a later date (for me anyway)

Leaves me with two possibilities
a) It no longer allows that format and would now have to be
(G:Var1) 0 == if{ } els{ if { } els{ if{ } esl{ if{ } els{ } } } } etc etc

Or

G:Vars can't be used in FSX for AI aircraft.
L:Vars DONT work!

Any ideas / suggestions?
 
Your first <Code></Code> example should work in FSX the same as in FS9.
Option a) is not necessary at all and option b) is a possibility. I've never tested AI mdl files, but if LVars don't work then it is more than probable that Gvars won't work either. I'll try to do some tests and see.

Tom
 
Your first <Code></Code> example should work in FSX the same as in FS9.
Option a) is not necessary at all and option b) is a possibility. I've never tested AI mdl files, but if LVars don't work then it is more than probable that Gvars won't work either. I'll try to do some tests and see.

Tom

Thanks Tom,
I have never been able to get L:Vars to work on an AI aircraft (FS9 or FSX), so that may not be an indication of G:Vars not working in FSX.

I have sent the code to my mate as -

(G:Var1) 1 ==
if{ } els{ if{ } els{ if{ } els{ } } }

I merged the (G:Var1) 0 == part as the final els in the code.
If that works then it has to be the -

(G:Var1) 0 ==
(G:Var1) 1 ==

that it doesn't like.

As an example of the way it looks when it doesn't work in FSX, but does work in FS9...

<code>
(G:Var1) 0 == if{ (A:PLANE ALT ABOVE GROUND,feet) if{ 100 } els{ 1 (&gt;G:Var1) 0 } }
(G:Var1) 1 == if{ (A:LIGHT STROBE,bool) if{ 0 } els{ 50 } }
</code>
 
Last edited:
Update

Hi Tom,
Just heard back from my mate....

Redone as -
(G:Var1) 1 == if{ els{ etc etc WORKS!

So doesn't work -
<code>
(G:Var1) 0 == if{ (A:PLANE ALT ABOVE GROUND,feet) if{ 100 } els{ 1 (&gt;G:Var1) 0 } }
(G:Var1) 1 == if{ (A:LIGHT STROBE,bool) if{ 0 } els{ 50 } }
</code>

Does work
(G:Var1) 1 ==
if{ (A:LIGHT STROBE,bool) if{ 0 } els{ 50 } }
els{ (A:PLANE ALT ABOVE GROUND,feet) if{ 100 } els{ 1 (&gt;G:Var1) 0 } }

[edit] Have asked him to try the original code again but use -
(G:Var1) 1 !=
(G:Var1) 1 ==

If that works it has to be the (G:Var1) 0 == that is the problem!

[edit2] (G:Var1) 0 == IS the problem!
The above works.
So the big question is....what value are G:Vars in FSX when first used????
 
Last edited:
If that works it has to be the (G:Var1) 0 == that is the problem!

(G:Var1) 0 == IS the problem!

It depends on what you define for a problem...

This is a perfect valid script:

Code:
<code>
(G:Var1) 0 == if{ (A:PLANE ALT ABOVE GROUND,feet) if{ 100 } els{ 1 (&gt;G:Var1) 0 } }
(G:Var1) 1 == if{ (A:LIGHT STROBE,bool) if{ 0 } els{ 50 } }
</code>

but if it doesn't work as you expect in this case you are right, but the code is not the problem, the result of the code is.

So, what does your script exactly need to do?

So the big question is....what value are G:Vars in FSX when first used????

GVars default to 0 when the gauge/mdl is loaded.

Another point: you stated that LVars don't work in AI aircraft. What kind of tests did you make to ensure that? I'm curious to know as I never worked with AI so far.

Tom
 
Thanks for checking....

L:Vars...I tried -
Took a working piece of XML anim code that used G:Vars.
Swapped them with L:Vars
Compiled
Looked at it in FS9....and....nothing.
The anim that previously worked with G:Vars didn't work at all.

The script is valid as

<code>
(G:Var1) 0 ==
(G:Var1) 1 ==
</code>

and the anim runs perfectly under FS9, there is no anim at all with FSX.

Changing it to a single G:Var check with a hoard of if/els works in both.

Change it to
<code>
(G:Var1) 1 !=
(G:Var1) 1 ==
</code>

and the animation works in FSX

So for some reason (G:Var1) is not 0 initially (should be the default according to the SDK) when the code is running under FSX, but it is 0 initially when running in FS9.
 
GVars default to 0 when the gauge/mdl is loaded.

That they do. It's easy enough to validate by simply "printing" the value immediately after declaring the G:var...

Code:
  <Element>
    <Position X="113" Y="102"/>
    <FormattedText X="300" Y="35" Font="Glass Gauge" FontSize="10" LineSpacing="0" Adjust="Left" Color="White" Bright="Yes">
      <String>GVariable = %((G:Var1))%!2.4f!</String>
    </FormattedText>
  </Element>
The resulting string value is 0.0000
 
Bill - I believe that John had sent you the code to look at last week.

If you change the first line to

(G:Var2) 1 !=

You will find it works!

So when it initialises all I know is it seems to be neither 1 or 0.

John has gone on holiday so I cant get him to check things at the moment, but would be interesting to see if -

(G:Var2) 1 &lt;

works.
 
OK this is starting to become irritating...

FS9 Works perfectly ....

<Code>
(G:Var2) 0 == if{ (A:PLANE ALT ABOVE GROUND,feet) 200 &gt; if{ 1 (&gt;G:Var2) 0 } els{ (A:VELOCITY BODY Z,knots) 10 &gt; (A:GENERAL ENG THROTTLE LEVER POSITION:1,percent) 40 &gt; &amp;&amp; if{ 0 } els{ 100 } } }
(G:Var2) 1 == if{ (A:VELOCITY BODY Z,knots) 100 &lt; if{ 2 (&gt;G:Var2) 100 } els{ 0 } }
(G:Var2) 2 == if{ (A:GEAR HANDLE POSITION,position) if{ 100 } els{ 0 (&gt;G:Var2) 0 } }
</Code>

FSX doesn't work at all!!!

A 'workaround' is to write it to specifically test for the G:Var = 1 or 2 and an else (ie all other numbers) for when it is supposed to = 0, then it works.
No other custom XML code is using (G:Var2), however some of the default FSX code does.

Something with G:Vars in FSX that is different from FS9, but I have no idea what!!!!
 
Last edited:
Further examples -

(a) FS9 - Works, but not in FSX

<Code>
(G:Var3) 0 == if{ (A:PLANE ALT ABOVE GROUND,feet) 100 &gt; if{ 1 (&gt;G:Var3) 100 } els{ (A:GENERAL ENG THROTTLE LEVER POSITION:1,percent) 95 &gt; if{ 125 } els{ 0 } } }
(G:Var3) 1 == if{ (A:VELOCITY BODY Z,knots) 25 &lt; if{ 0 (&gt;G:Var3) 0 } els{ 100 } }
</Code>

To get to work in FSX either -
(b)
<Code>
(G:Var3) 1 != if{ (A:PLANE ALT ABOVE GROUND,feet) 100 &gt; if{ 1 (&gt;G:Var3) 100 } els{ (A:GENERAL ENG THROTTLE LEVER POSITION:1,percent) 95 &gt; if{ 125 } els{ 0 } } }
(G:Var3) 1 == if{ (A:VELOCITY BODY Z,knots) 25 &lt; if{ 0 (&gt;G:Var3) 0 } els{ 100 } }
</Code>

Or
(c)
<Code>
(G:Var3) 1 == if{ (A:VELOCITY BODY Z,knots) 25 &lt; if{ 0 (&gt;G:Var3) 0 } els{ 100 } }
els{ (A:PLANE ALT ABOVE GROUND,feet) 100 &gt; if{ 1 (&gt;G:Var3) 100 } els{ (A:GENERAL ENG THROTTLE LEVER POSITION:1,percent) 95 &gt; if{ 125 } els{ 0 } } }
</Code>

So for some reason the G:Var does not initialise at 0 in FSX using (a) or the first section would be triggered, and as the second section doesn't kick in either, its not 1 either.
In (b) 1 != triggers the first section (so its not initialised at 1)
In (c) the els triggers the second section (so its not initialised at 1)

So what value is the damn thing being initialised at? I know its supposed to be 0!
 
Did you try testing by -1 == instead of 0 == ?

AI and MP aircraft are treated different by FSX than the user aircraft.
In those the entire gaugeset is not loaded, thus all user vars (L-C-G) are inoperative as there is no instantiation of gaugeclasses, which are subclasses of the user aircraft (I guess this last one the reason for RELOAD_PANELS not working anymore).
However, despite an .MDL is processed by FS as a single gauge for the user aircraft, I suspect the GVars in AI/MP cases might be treated different, ie when undefined (not assigned any value), they might return an ERROR flag (-1).
You could make some tests, for example updating with 0, like:

(G:Var3) 1 != if{ 0 (>G:Var3) }
(G:Var3) 0 == if{ does it work? }

Also would be nice that you make your AI flyable and check if the (a) example that works in FS9 works in a user aircraft as well.

Tom
 
Thanks Tom, I think you may be right.
Just heard back from the guy I am doing the XML and on a hunch I used...

(G:Var1) 1 != (G:Var1) 0 != and if { etc etc }
(G:Var1) 1 == if{ etc etc }
(G:Var1) 2 == if{ etc etc }

And it worked perfectly in FSX

The second and third lines include G:Var assignments so I know your suggestion works.

So how to check for and assign -1 to a G:Var, do I have to negate, or can I just use -1?

Or I guess I could use (G:Var1) 1 &lt; on the first line?
 
You can use -1 directly.

1 &lt; should work as well but the interesting point is to see whether Gvar default var is ERROR (-1), which would be logical, or any other value different from 0.

Tom
 
Take a bow, you are a genius!

(G:Var1) 0 &lt;= if{ etc etc }
(G:Var1) 1 == if{ etc etc }
(G:Var1) 2 == if{ etc etc }

Works in FSX.

So has to be -1.
One to remember.... G:Vars for AI aircraft in FSX initialise at -1.
Good thing is using 0 &lt;= will also work in FS9.

Thanks!

Kev
 
Guess I spoke too soon.

It works about 50% of the time.

Funnily enough the same model using the same code with 0 == compiled with makemdl not only works in FS9, but in FSX also!

Something with xtomdl is the problem?
 
Another update...

Looks like I will be dropping G:Vars for AI aircraft compiled with xtomdl.

Got John to do a test with...

l10 0 == if{ 100 } els{ 50 }

And it appeared to work. AI aircraft 'spawned' with gear down (100) 100% of the time, even without doing a 0 s10 beforehand. So these do appear to 'start' with 0 as a value.

So just a quickie....

if{ 0 (&gt;G:Var1) 100 }
Would usually result in 0 being assigned to G:Var1 and 100 being returned as the keyframe.

I am guessing the equivalent would be ....
if{ 0 sp10 100 }


Also any drawbacks to this method apart from making the code look more abstract.

Cheers

[edit] Forgot to ask..
can I use the method above (l,s,sp) to store and read a string i.e.

'my string' s11

l11 'my string' scmi ! if{ 1 } els{ 0 }
 
Last edited:
So just a quickie....

if{ 0 (&gt;G:Var1) 100 }
Would usually result in 0 being assigned to G:Var1 and 100 being areturned as the keyframe.

I am guessing the equivalent would be ....
if{ 0 sp10 100 }

The difference between GVars and registers s/l is that these last ones are reset to 0 on every cycle, while GVars, like LVars, retain their values once assigned.
But in this specifically case, I guess there would be the same using vars or registers, providing they are continually assigned at runtime.

[edit] Forgot to ask..
can I use the method above (l,s,sp) to store and read a string i.e.

'my string' s11

l11 'my string' scmi ! if{ 1 } els{ 0 }

Yes you can, registers store bytes of data directly.

Tom
 
Thanks Tom, you are going to love this....

Got John to do some basic tests.....

(G:Var) 0 == if{ 1 } els{ 0 }
works as you would expect

(G:Var) 0 == if{ 1 }
(G:Var) 1 == if{ 0 }
doesn't work as we already know

(G:Var) 0 == if{ 1 } (G:Var) 1 == if{ 0 }
DOES WORK

Putting the two expressions on a single line makes it work, I'm speechless and very confused!
 
I'm rather confused.

(G:Var) 0 == if{ 1 } (G:Var) 1 == if{ 0 }
DOES WORK


What does it mean? Return value is 1 or 0?

Putting the expression in one line versus multiple lines makes no sense, as control chars embedded in scripts (Enter, Tab, Backspace,etc) are ignored by the parser at runtime.

Tom
 
Sorry Tom should have given a bit more info...

I got him to create a cube.

The code is a visibility on/off

So


<Code>
(G:Var4) 0 == if{ 1 } (G:Var4) 1 == if{ 0 }
</Code>

If the GVar is initialised at 0 the cube shows, and it did.

<Code>
(G:Var4) 0 == if{ 1 }
(G:Var4) 1 == if{ 0 }
</Code>

No cube showed up, so either it didn't initialise at 0 (which we now know it does) or something weird is going on.

Same code just different 'format'.

Will get him to retest.

[additional]
I had a look at the default code in the modeldef for similar examples where they use the same method.
Found - switch_fuel_selector_LBRO
Had a look at the code...
Is it just me or is there a } missing from the default code for this part. There are 6 x { but only 5 x }
Its either missing from the end of the code for the els{ (M:X) ......
Or its missing from the end of the case != if{ ......

Now I am confused.
 
Last edited:
Back
Top