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 va...
 
Notifications
Clear all

Addressing local variables? Redwing Constellation MSFS2024

Posts: 5
Registered
Topic starter
(@f16jockey)
Joined: 1 day ago

I'm trying to assign an axis to the cowl flaps for the Redwing Constellation.
Not really an axis, more like a three position switch: if the lever is put into the top 6000, the Cowl Flap value should raise, in the lower 6000 it should lower and in the middle range it should do nothing.

As a base, I made a lua script something like

while true do 
   local cowl_axis = ipc.readSW(0x66C2) --This is assigned to the correct axis
   if cowl_axis < -6000 then 
      -- Upper region
   elseif cowl_axis > 6000 then 
      -- Lower region
    end 
  ipc.sleep(50) 
end

The above works (my axis acts in reverse, low is 16383 and high is -16384).
But I'm stuck where I've written --Upper Region and --Lower Region

In the code of the switch (via Behaviours Tool) I see the value of the Cowl Flap is stored in L:1:CowlFlaps_1
I'm unfamiliar with this notation, but it seems to be a local variable (as seen in the attached pics).

I'm unable to read or write this variable.
I use the same notation as I see it in the code, but this is most probably wrong.
For example

local current_pos = ipc.readLvar("L:1:CowlFlaps_1")

always returns nil.

Equally my attempt to write back a higher (or lower) value doesn't work, as could be expected.

local new_pos = math.min(100, current_pos + 1.0)
ipc.writeLvar("L:1:CowlFlaps_1", new_pos)

What's the proper way to access that local variable CowlFlaps_1 ?

I hope someone can help me in this, because the Cowl Flaps and Oil Cooler Flaps operation is really dramatic with this aircraft.

Best regards,
Wim

 

 

 


8 Replies
Posts: 332
Admin
(@fsuipc)
Joined: 11 months ago

When a lvar is notated as 'L:1', it means that it is a scoped lvar, which are different from standard lvars and cannot be read or written via the normal lvar interface. The only way to write them is to use calculator code, and the only way to read their value is to copy it to a standard lvar and then read that lvar.

So to update the value, use
   ipc.executeCalcCode(new_pos .. " (>L:1:CowlFlaps_1)")

You can also create a preset in your myevents.txt file:

    My Redwing Cowl Dlaps#$Param (>L:1:CowlFlaps_1)

and assign to that, with a parameter. Or, alternatively, you can create 3 presets, one for each position, with the correct value (instead of $Param) for each position.

Also, rather than using lua, you can assign your axis using the right-hand side of the axis assignment panel to send the required preset when entering an axis range.


Reply
Posts: 5
Registered
Topic starter
(@f16jockey)
Joined: 1 day ago

Thanks for the quick reply.

I understand most of the suggested options, except...

Posted by: @fsuipc

and the only way to read their value is to copy it to a standard lvar and then read that lvar.

You mean keeping track my own Lvar L:ConnieCowlFlaps, modify that Lvar with my axis driven script and then send it to the aircraft's scoped var with calculator code to keep it synced?
And never use anything else but my own script, because otherwise the sync will be lost?

Wim


Reply
Posts: 5
Registered
Topic starter
(@f16jockey)
Joined: 1 day ago

Dived into the manual...
When looking at the 2nd pic in my OP, copying the scoped var would be like below?

(L:ENGINE_LEVER_COWLFLAPS_1:COWLFLAPS_1, number) (>L:ConnieCowlFlaps_1, number)

Is that correct?

Wim

 


Reply
Posts: 332
Admin
(@fsuipc)
Joined: 11 months ago

Posted by: @f16jockey

You mean keeping track my own Lvar L:ConnieCowlFlaps, modify that Lvar with my axis driven script and then send it to the aircraft's scoped var with calculator code to keep it synced?

No! You update the scoped lvar via calculator code (or a preset), as I have showed. You only need to copy the scoped lvar value to a standard one if you need to read the value, but to control the lvar you do not need to do this.

It is a pain to read the value of a scoped lvar as you have to sync it every time before a read, and this is really not worth doing unless you have a very good reason to do this,

Posted by: @f16jockey

(L:ENGINE_LEVER_COWLFLAPS_1:COWLFLAPS_1, number) (>L:ConnieCowlFlaps_1, number)

Is that correct?

I thought the (scoped) lvar was L:1:CowlFlaps_1, so it should be

(L:1:CowlFlaps_1, number) (>L:MyCowlFlaps_1, number)

(or whatever lvar name you want to use!)

Note also that there is a delay between writing/updating the value to the lvar and the new lvar value being available in FSUIPC7, and the length of the delay depends on the lvar update frequency, which is at 6Hz (by default). So you would need to wait for up to 170ms or so before the new value can be read. Also, an additional issue, is that the lvar will only be created the first time you write to it, and so it will also not be visible to FSUIPC7 until a WASM reload is performed.

Due to these difficulties, it really isn't worth doing this unless you really have a good reason to know the value of the scoped lvar. To assign to control the lvar, you do not need to know its current value.


Reply
Page 1 / 2