Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi John,

Below are two tiny Lua scripts to calculate the total weight (e.g., landing weight) of a plane (Learjet in this case). If I run the scripts a number of times as the plane flies and burns off fuel, the first two-line script using an offset works reliably and always provides the correct updated weight.

However, the second script that creates the Lvar Lear_LDG_Weight in order to read the TOTAL WEIGHT Avar fails approximately 40 to 50 percent of the time. When it fails the script usually reports the initial value used when creating the Lvar (the 10361 value), or just doesn't update from the previous value.  Using the sim's SimVar tool I monitored the TOTAL WEIGHT simvar and it always was continually updating as expected. I assume the (0x30C0) offset is using that simvar value. 

The main purpose of this post is to make sure I understand the Lvar creation process. It was the "Lvar script" that I tried first until seeing it was not working reliably. If the code in the Lvar script looks correct to you, then I would assume the sim may have some kind of a timing issue. This happens in both MSFS2020 and MSFS2024. 

I know you are on Holiday and this issue can certainly wait until a convenient time.

Thanks,

Al

ldg_wt = ipc.readDBL(0x30C0)                       -- get total weight
ldg_wt = math.floor(ldg_wt_offset + 0.5)       -- round to no decimal places

====================================================================================================

 ipc.createLvar("L:Lear_LDG_Weight",10361)                                                  -- create Lvar, just using Lear's empty weight as the initial value
 ipc.reloadWASM()
 ipc.sleep(1000)
 ipc.execCalcCode(" (A:TOTAL WEIGHT, pounds) (>L:Lear_LDG_Weight) ")    -- get current total weight
 ipc.sleep(100)
 ldg_wt = ipc.readLvar("L:Lear_LDG_Weight")
 ldg_wt = math.floor(ldg_wt + 0.5) 

  • ark1320 changed the title to Creating Lvar Timing Issue?

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.