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

FS2004 Incrementing var values

Messages
1,468
Country
italy
I'm trying to increment an L:var but it's not working
Code:
<Value>[COLOR="Red"](L:FLD_Control,bool) 1 ==[/COLOR] if{ [COLOR="Red"][COLOR="Blue"](L:FLD_Rate,number) (L:FLD_Conv,number) * near 60 / 18 / (>L:C2_uplift rate,number)[/COLOR][/COLOR]
if{ [COLOR="Magenta"](L:C2_uplift rate,number) 1 ++ (>L:FUEL TANK CENTER2 QUANTITY, number) [/COLOR]} } </Value>

the flag is set to 1
if so set the fuel uplift rate and put it into a var
now I'm trying to increment the L:FUEL TANK CENTER2 QUANTITY, number var but it refuses to move.

What's wrong?
Vololiberista
 
Does the purple part even execute?
The way I see it is that the blue part puts the result of the calulation in the Lvar and then leaves nothing that is true on the stack for the following if{ }.
 
The blue part does work and depending on how I set the uplift rate changes the value of (L:C2_uplift rate,number) even on the fly which is what I want there.

However, as you say the purple bit doesn't work. I want to continuously increment (L:FUEL TANK CENTER2 QUANTITY, number) by the value of (L:C2_uplift rate,number) until the flag is reset to 0.

vololiberista
 
The problem is here:

(L:C2_uplift rate,number) 1 ++ (>L:FUEL TANK CENTER2 QUANTITY, number)

Instead of incrementing (L:C2_uplift rate,number), you are incrementing the 1 value, so what is assigned to (L:FUEL TANK CENTER2 QUANTITY, number) is always 2. Using only one + sign solves the conflict.

Tom
 
Thanks Tom.
However, I can't get your solution to work nor can I any other. It seems perhaps that one can only increment a variable by a number and not another variable.

All the examples I have are click repeats and have the same var incrementing itself by a number.

If you or anyone has an example of a variable being incremented by another not just once but continuously I'd like to see how it's done.

I've tried variation after variation and the fuel variable refuses to change.
There's nothing wrong with its state. I've tested that too i.e. I can easily add or subtract a number and that changes it. But, what I want is as above otherwise what I want to do is pretty much dead in the water.
vololiberista
 
It seems that I will have to check your complete code examples always...:)


Code:
<Value>(L:FLD_Control,bool) 1 == 
if{ (L:FLD_Rate,number) (L:FLD_Conv,number) * near 60 / 18 / (>L:C2_uplift rate,number)
  (L:C2_uplift rate,number) (>L:FUEL TANK CENTER2 QUANTITY, number) }
 </Value>

FS's script operations does not care at all whether a value pushed in the stack comes from a variable, a number or whatever; they are all saved as bytes and converted to the proper type (number/string) when they are popped as a result of an operation (arithmetical, var assignment, etc.)

Tom

EDIT: Assuming you are increasing the tank quantity by the uplift rate factor, the correct code should be:

(L:FUEL TANK CENTER2 QUANTITY, number) (L:C2_uplift rate,number) + (>L:FUEL TANK CENTER2 QUANTITY, number)
 
Last edited:
I havent played around with XML enough to know whether or not the following is true(have since switched to C++), but FUEL TANK CENTER2 QUANTITY is the name of a A variable. Wont that give problems? FWIW though if you are trying to set the actual level of a fuel tank you arent going to get anywhere with XML. Only possible via C++/SimConnect.
 
I havent played around with XML enough to know whether or not the following is true(have since switched to C++), but FUEL TANK CENTER2 QUANTITY is the name of a A variable. Wont that give problems?

Not at all, LVar and AVar names are not related.

Tom
 
Hi NK,
The problem has arrisen because I cannot get (A:FUEL TANK CENTER2 QUANTITY, number) to work with Doug's fuel gauge. All the other tanks work perfectly. So I'm having to fake it!!!
I'm converting the A:var into an L:var and gallons into kilos
Code:
<Value>(L:ct2_min,bool) 0 == if{ (A:FUEL TANK CENTER2 QUANTITY, gallons) 3.4231 * (>L:FUEL TANK CENTER2 QUANTITY, number) if{ (L:FUEL TANK CENTER2 QUANTITY, number) 0 &gt; 1 (>L:ct2_min,bool) } }</Value>

Then finding out what the uplift rate is and putting that into (>L:C2_uplift rate,number)
Code:
<Value>(L:FLD_Control,bool) 1 == if{ (L:FLD_Rate,number) (L:FLD_Conv,number) * near 60 / 18 / (>L:C2_uplift rate,number) } </Value>

Then trying and failing to increment (>L:FUEL TANK CENTER2 QUANTITY, number)
Code:
<Value>(L:FLD_Control,bool) 1 == if{ (L:FUEL TANK CENTER2 QUANTITY, number)  1.48 * ++ (>L:FUEL TANK CENTER2 QUANTITY, number) } </Value>

Tom, the 1.48 represents the value of L:C2_uplift rate,number being 1,600kgs per minute. What you see above is me trying anything!!
This actually got it to work but only for 18 cycles!!! incrementing the tank from 56 kgs to just 84kgs!

It's very kind of you to "offer" to run through "all" my code as always :) :)
and I'll try your lates solution above again (I'm pretty sure I tried that and didn't get it to work).
vololiberista
 
Tom,
your code
Code:
(L:FUEL TANK CENTER2 QUANTITY, number) (L:C2_uplift rate,number) + (>L:FUEL TANK CENTER2 QUANTITY, number)
changed the value from 56.19 to 57.67 and stopped. So it incremented only once! how then can I get it to repeatedly increment until say a switch is turned off?
vololiberista
 
changed the value from 56.19 to 57.67 and stopped. So it incremented only once! how then can I get it to repeatedly increment until say a switch is turned off?
vololiberista

You could try something like this as one approach:

Code:
<Update>
  (L:SwitchPosition, bool) 1 ==
    if{
      (L:FUEL TANK CENTER2 QUANTITY, number) (L:MaxTankCenter2Quantity, number) >= if{ 0 (>L:SwitchPosition, bool) g101 }
      (L:FUEL TANK CENTER2 QUANTITY, number) (L:C2_uplift rate,number) 18 / + (>L:FUEL TANK CENTER2 QUANTITY, number)
      :101
    }
</Update>

where the fourth line is just a check to see if desired maximum tank quantity is already reached ... then switch is automatically turned off. You may not require such a check, I dunno.

Fifth line includes 18 / because the incrementing will be quite rapid as this script is executed each Update cycle when SwitchPosition is 1. Experiment with the value 18 or C2_uplift rate for desired pace of tank fill.

Or, if the switch should not automatically be turned off:

Code:
<Update>
  (L:SwitchPosition, bool) 1 == (L:FUEL TANK CENTER2 QUANTITY, number) (L:MaxTankCenter2Quantity, number) &lt; and
    if{
      (L:FUEL TANK CENTER2 QUANTITY, number) (L:C2_uplift rate,number) 18 / + (>L:FUEL TANK CENTER2 QUANTITY, number)
    }
</Update>

Cheers,

Bob
 
Last edited:
It's really a little more complex than that Bob.
both the centre tank and centre2 tank have a second yellow pointer.
1. When filling from the bowser the pointer is set to the fuel cut-off point.
2. In flight it's necessary to be able to transfer fuel between both tanks so the pointers are set accordingly and when the valves are opened the fuel flows into one tank and out of the other.
3. Also you may notice that in my code the uplift rate can be changed. Technically the max rate is 1,600kpm. But for the in flight transfers it has to be the equivalent of gravity feed. So it's quite important
that L:C2_uplift rate,number) is variable. Also there's one switch for the bowser uplift and others to govern the inter tank transfers.
L:C2_uplift rate,number) also takes into account the value at 18 times a second. Hence the value 1.48 which is 1,600kpm / 60 / 18

Having an update function would seem to complicate the process though I'll try it out.

It seems crazy that XML doesn't seem to be able to handle a simple operation like: [if A increment X by Y until Z]. That's all I want to do!!!!!
vololiberista
 
Last edited:
Bob,
Unfortunately your updates do exactly the same as Tom's suggestion above in that they increment the var only once!

So it would appear that XML cannot increment continously unless you use

<Click Repeat="Yes"> which is incorrect in this instance and quite impracticable.

vololiberista
 
It's not crazy. Remember that the XML code is called and executed at regular intervals.

The effect of your example would be the same as setting X = Z on the first call.

You need to spread your calculation across several calls. The following psuedo-code suggests one way:

Code:
C

if (TransferRequested && Fuel < FuelRequired)
	{
	Fuel = Fuel + FuelFlowRate * TimeInterval;
	}

XML??

TransferRequested Fuel FuelRequired < &&
	if{Fuel FuelFlowRate TimeInterval * +}
 
In this case though I'm not actually using fuel. Primarily because the CENTER2 won't work with Doug's fuel gauge.
I'm using L:vars instead to simulate fuel in the CENTER2 tank.

This is my pseudo code!!!: a (representing a switch) z (representing value to be attained)
if a=true then add y to x until x=z

Even visual basic can do that!!!! XML?????

As I said above it would seem that holding down a mouse button until the value is reached is the only way. I may be mistaken of course but although it would work it is totally impracticable.
vololiberista




vololiberista
 
Hi NK,
The problem has arrisen because I cannot get (A:FUEL TANK CENTER2 QUANTITY, number) to work with Doug's fuel gauge. All the other tanks work perfectly. So I'm having to fake it!!!
I'm converting the A:var into an L:var and gallons into kilos
Code:
<Value>(L:ct2_min,bool) 0 == if{ (A:FUEL TANK CENTER2 QUANTITY, gallons) 3.4231 * (>L:FUEL TANK CENTER2 QUANTITY, number) if{ (L:FUEL TANK CENTER2 QUANTITY, number) 0 &gt; 1 (>L:ct2_min,bool) } }</Value>

Then finding out what the uplift rate is and putting that into (>L:C2_uplift rate,number)
Code:
<Value>(L:FLD_Control,bool) 1 == if{ (L:FLD_Rate,number) (L:FLD_Conv,number) * near 60 / 18 / (>L:C2_uplift rate,number) } </Value>

Then trying and failing to increment (>L:FUEL TANK CENTER2 QUANTITY, number)
Code:
<Value>(L:FLD_Control,bool) 1 == if{ (L:FUEL TANK CENTER2 QUANTITY, number)  1.48 * ++ (>L:FUEL TANK CENTER2 QUANTITY, number) } </Value>

Tom, the 1.48 represents the value of L:C2_uplift rate,number being 1,600kgs per minute. What you see above is me trying anything!!
This actually got it to work but only for 18 cycles!!! incrementing the tank from 56 kgs to just 84kgs!

It's very kind of you to "offer" to run through "all" my code as always :) :)
and I'll try your lates solution above again (I'm pretty sure I tried that and didn't get it to work).
vololiberista

Vololiberista,

It's very reasonable that you can't get my example to work because you still have errors in other parts of your code. It use to happen in most of your examples, you post a basic snippet and tell us that the rest is working ok when it is not, turning the solution into kind of a big guess (please take this as a constructive critic:))

In this part:

Code:
<Value>(L:ct2_min,bool) 0 == if{ (A:FUEL TANK CENTER2 QUANTITY, gallons) 3.4231 * (>L:FUEL TANK CENTER2 QUANTITY, number) if{ (L:FUEL TANK CENTER2 QUANTITY, number) 0 &gt; 1 (>L:ct2_min,bool) } }</Value>

(L:ct2_min,bool) will never equal 1, so FTC2Quantity LVar is constantly being reset by the equivalent AVar, which leads to most of your problems.

My strong advise is that you first check your scripts for other possible errors, make new tests and then post what may still be working unproperly so we can focus on the logic instead of the syntax ;)

Tom
 
if a=true then add y to x until x=z

Even visual basic can do that!!!! XML?????

I think you are still missing the point I made in Post #15. XML code is handled differently to VB or C. It's run in a loop by FS and the XML gauges are updated (that is called and executed) at regular intervals. By default this rate is 16Hz although it can be changed by including <Update Frequency=n/>

If you included code like if a=true then add y to x until x=z then the first time the gauge is called the loop would run to completion and set x=z immediately.
 
Last edited:
Back
Top