These are the Support Forums for FSUIPC and related products.
These forums replace the old support forums which have been running for 20+ years. The old forums contain a wealth of information on all FSUIPC products, but are now no longer available.
Please note that you will need to Register and Login to post for support, and also to download attachments. You can view these forums without registering.
Support is also available via Discord. Please use the following invite link to join the FSUIPC Discord server:
https://discord.gg/zjwUTrxmmE
Addressing local variables? Redwing Constellation MSFS2024
Here's a demo lua script that shows how to keep a scoped lvar synced with a standard lvar. The script should be auto-ran, preferably only in the profile for the aircraft that contains the scoped lvar that you want to read.
--
-- Demo script on how to sync a scoped lvar to a standard lvar.
-- This allows the lvar to be read or added to an FSUIPC offset.
-- Note that you should not write to this lvar (read-only).
-- To update a scoped lvar, use calculator code or a preset
--
-- This demo script will sync the value of the scoped lvar L:1:CowlFlaps_1
-- to the standard lvar L:MyCowlFlaps_1
--
-- First, create the lvar we are going to use
ipc.execCalcCode("(L:1:CowlFlaps_1, number) (>L:MyCowlFlaps_1, number)")
-- Reload the lvars in the WASM
ipc.ReloadWASM()
-- Wait for the new lvar list to be received
ipc.sleep(200)
-- timer function to sync the scoped lvar with our lvar
function SynScopedLvars(time)
ipc.execCalcCode("(L:1:CowlFlaps_1, number) (>L:MyCowlFlaps_1, number)")
end
-- Set an event timer to sync the lvars
event.timer(167, "SynScopedLvars")
This would sync the lvar at roughly 6Hz, so at the same frequency as lvar updates are pushed from the FS to FSUIPC7. This implies a maximum delay from between the scoped lvar change and the standard lvar being updated and seen of around 333ms.
@fsuipc I only noticed this post after posting my script. I'll add your ReloadWASM() suggestion at the start of my script 'cos I noticed some issues when running the script in the first session of a cold started sim.
Thanks for the help, my script is up and running.
My reason for wanting to read the current value of the scoped lvar: I wanted a possibility to control the cowl flaps and oil cooler flaps, without blocking the option to let the Artificial Flight Engineer control them as well.
-- =================================================================
-- REDWING CONSTELLATION - HYBRIDE COWL FLAPS & OIL COOLERS
-- =================================================================
-- COLD START INITIALISATIE: Force the sim to create the global L:Vars
ipc.execCalcCode("0 (>L:MyCowlFlaps_1, number) 0 (>L:MyCowlFlaps_2, number) 0 (>L:MyCowlFlaps_3, number) 0 (>L:MyCowlFlaps_4, number)")
ipc.execCalcCode("0 (>L:MyOilCoolers_1, number) 0 (>L:MyOilCoolers_2, number) 0 (>L:MyOilCoolers_3, number) 0 (>L:MyOilCoolers_4, number)")
-- Give FSUIPC7 some time
ipc.sleep(500)
-- Internal status Cowl Flaps (Axis 4)
local cowl_1, cowl_2, cowl_3, cowl_4 = 0, 0, 0, 0
local cowl_sync = true
-- Internal status Oil Coolers (Axis 5)
local oil_1, oil_2, oil_3, oil_4 = 0, 0, 0, 0
local oil_sync = true
local step = 2.0
while true do
-----------------------------------------------------------------
-- 1. COWL FLAPS SECTION (Axis 4 - Offset 0x66C2)
-----------------------------------------------------------------
local cowl_axis = ipc.readSW(0x66C2)
if cowl_axis < -9000 then
-- OPEN
if cowl_sync then
ipc.execCalcCode("(L:1:COWLFLAPS_1, number) (>L:MyCowlFlaps_1, number)")
ipc.execCalcCode("(L:1:COWLFLAPS_2, number) (>L:MyCowlFlaps_2, number)")
ipc.execCalcCode("(L:1:COWLFLAPS_3, number) (>L:MyCowlFlaps_3, number)")
ipc.execCalcCode("(L:1:COWLFLAPS_4, number) (>L:MyCowlFlaps_4, number)")
ipc.sleep(100)
cowl_1 = ipc.readLvar("L:MyCowlFlaps_1") or 0
cowl_2 = ipc.readLvar("L:MyCowlFlaps_2") or 0
cowl_3 = ipc.readLvar("L:MyCowlFlaps_3") or 0
cowl_4 = ipc.readLvar("L:MyCowlFlaps_4") or 0
cowl_sync = false
end
cowl_1 = math.min(100, cowl_1 + step)
cowl_2 = math.min(100, cowl_2 + step)
cowl_3 = math.min(100, cowl_3 + step)
cowl_4 = math.min(100, cowl_4 + step)
ipc.execCalcCode(string.format("%f (>L:1:CowlFlaps_1) %f (>L:1:CowlFlaps_2) %f (>L:1:CowlFlaps_3) %f (>L:1:CowlFlaps_4)", cowl_1, cowl_2, cowl_3, cowl_4))
elseif cowl_axis > 9000 then
-- CLOSE
if cowl_sync then
ipc.execCalcCode("(L:1:COWLFLAPS_1, number) (>L:MyCowlFlaps_1, number)")
ipc.execCalcCode("(L:1:COWLFLAPS_2, number) (>L:MyCowlFlaps_2, number)")
ipc.execCalcCode("(L:1:COWLFLAPS_3, number) (>L:MyCowlFlaps_3, number)")
ipc.execCalcCode("(L:1:COWLFLAPS_4, number) (>L:MyCowlFlaps_4, number)")
ipc.sleep(100)
cowl_1 = ipc.readLvar("L:MyCowlFlaps_1") or 0
cowl_2 = ipc.readLvar("L:MyCowlFlaps_2") or 0
cowl_3 = ipc.readLvar("L:MyCowlFlaps_3") or 0
cowl_4 = ipc.readLvar("L:MyCowlFlaps_4") or 0
cowl_sync = false
end
cowl_1 = math.max(0, cowl_1 - step)
cowl_2 = math.max(0, cowl_2 - step)
cowl_3 = math.max(0, cowl_3 - step)
cowl_4 = math.max(0, cowl_4 - step)
ipc.execCalcCode(string.format("%f (>L:1:CowlFlaps_1) %f (>L:1:CowlFlaps_2) %f (>L:1:CowlFlaps_3) %f (>L:1:CowlFlaps_4)", cowl_1, cowl_2, cowl_3, cowl_4))
else
-- NEUTRAL - Do nothing but prepare to read the current values
if not cowl_sync then cowl_sync = true end
end
-----------------------------------------------------------------
-- 2. OIL COOLER FLAPS SECTION (Axis 5 - Offset 0x66C4)
-----------------------------------------------------------------
local oil_axis = ipc.readSW(0x66C4)
if oil_axis < -9000 then
-- OPEN
if oil_sync then
ipc.execCalcCode("(L:1:CONST_COOLER_1, number) (>L:MyOilCoolers_1, number)")
ipc.execCalcCode("(L:1:CONST_COOLER_2, number) (>L:MyOilCoolers_2, number)")
ipc.execCalcCode("(L:1:CONST_COOLER_3, number) (>L:MyOilCoolers_3, number)")
ipc.execCalcCode("(L:1:CONST_COOLER_4, number) (>L:MyOilCoolers_4, number)")
ipc.sleep(100)
oil_1 = ipc.readLvar("L:MyOilCoolers_1") or 0
oil_2 = ipc.readLvar("L:MyOilCoolers_2") or 0
oil_3 = ipc.readLvar("L:MyOilCoolers_3") or 0
oil_4 = ipc.readLvar("L:MyOilCoolers_4") or 0
oil_sync = false
end
oil_1 = math.min(100, oil_1 + step)
oil_2 = math.min(100, oil_2 + step)
oil_3 = math.min(100, oil_3 + step)
oil_4 = math.min(100, oil_4 + step)
ipc.execCalcCode(string.format("%f (>L:1:CONST_COOLER_1) %f (>L:1:CONST_COOLER_2) %f (>L:1:CONST_COOLER_3) %f (>L:1:CONST_COOLER_4)", oil_1, oil_2, oil_3, oil_4))
elseif oil_axis > 9000 then
-- CLOSE
if oil_sync then
ipc.execCalcCode("(L:1:CONST_COOLER_1, number) (>L:MyOilCoolers_1, number)")
ipc.execCalcCode("(L:1:CONST_COOLER_2, number) (>L:MyOilCoolers_2, number)")
ipc.execCalcCode("(L:1:CONST_COOLER_3, number) (>L:MyOilCoolers_3, number)")
ipc.execCalcCode("(L:1:CONST_COOLER_4, number) (>L:MyOilCoolers_4, number)")
ipc.sleep(100)
oil_1 = ipc.readLvar("L:MyOilCoolers_1") or 0
oil_2 = ipc.readLvar("L:MyOilCoolers_2") or 0
oil_3 = ipc.readLvar("L:MyOilCoolers_3") or 0
oil_4 = ipc.readLvar("L:MyOilCoolers_4") or 0
oil_sync = false
end
oil_1 = math.max(0, oil_1 - step)
oil_2 = math.max(0, oil_2 - step)
oil_3 = math.max(0, oil_3 - step)
oil_4 = math.max(0, oil_4 - step)
ipc.execCalcCode(string.format("%f (>L:1:CONST_COOLER_1) %f (>L:1:CONST_COOLER_2) %f (>L:1:CONST_COOLER_3) %f (>L:1:CONST_COOLER_4)", oil_1, oil_2, oil_3, oil_4))
else
-- NEUTRAL ZONE - Do nothing but prepare to read the current values
if not oil_sync then oil_sync = true end
end
ipc.sleep(50)
end
Best regards,
Wim
That looks ok, but please understand a few things about creating lvars and their access in FSUIPC7. This very much depends on the way lvars are created, and also the WASM settings that automatically discover and force new lvars to interested clients.
First, if you create lvars via FSUIPC standards methods, which are
1. using the lua function ipc.createLvar
2. via writing to offset 0x0D70
then a WASM reload will automatically be issued, but there will still be a delay of around 200ms max before the lvar becomes available.
If lvars are created any other way, e.g. by sending calc.code strings, created by 3rd party apps or even MSFS itself, then these will not be "known" to FSUIPC unless you issue a 'reload' command to the WASM.
There are various WASM parameters that control the scanning for lvars and thus the visibility of lvars in FSUIPC, but in the default configuration the scanning for new lvars stops 2 minutes after aircraft load. So if any lvars are created after this period, unless they are explicitly created via the FSUIPC functions already mentioned, then they will not be visible until a WASM reload call has been made (by any client).
Regards,
John
