There are a few things that could be improved in the script:
1. You only need to create the lvar once, do you should handle this if the script is being called multiple times.
2. If you create an lvar using ipc.creatLvar, you don't need to reload the WASM afterwards - this is done automatically.
As for the timing issue, lvar values are, by default, updated and send out from the WASM at a frequency of 6Hz, so roughly every 166ms.Therefore a delay of 100ms is not going to be enough most of the time, although this depends on the timings. Taking into account the time needed to send and process the request, you would need a delay of 200ms to make sure the new value had been received. if you want faster updates, you can set the WASM ini parameter LvarUpdateFrequency to VisualFrame.
if ipc.getLvarId("L:Lear_LDG_Weight") == nil then
ipc.createLvar("L:Lear_LDG_Weight",10361)
ipc.sleep(600)
end
ipc.execCalcCode(" (A:TOTAL WEIGHT, pounds) (>L:Lear_LDG_Weight) ") -- get current total weight
ipc.sleep(200)
ldg_wt = ipc.readLvar("L:Lear_LDG_Weight")
ldg_wt = math.floor(ldg_wt + 0.5)