Jump to content
The simFlight Network Forums

How to write offset value into a local var using lua script in FSUIPC?


Pantu

Recommended Posts

Hi,

could someone help me please?

I´m trying to write the value from an offset into a Lvar using a lua script in FSUIPC 6.

The task is to monitor an offset, e.g. the battery master switch, and when the value changes, writing the new value into my declarded local variable.

This would be needed for Lorbys Axis and ohs realizing an interactive voice checklist.

Axis and ohs only accepts Lvariables, no offsets. SimVars wouldn´t do as I´m using Project Magenta´s Boeing suite. together with P3Dv5.3

Following script unfortunately won´t do the job:

----------------------------------------------------script---------------------------------

local Battery_on = {}
function Batteryswitch(offset, val)
                  if value == 1 then
                   ipc.writeLvar("Battery_on", 1)
    else
                   ipc.writeLvar("Battery_on", 0)
    end
end
event.offsetmask(0x281C, 1,"UB","Batteryswitch")  --- bit 0

--------------------------------------------------------------------------------------------

What am I doing wrong?

Any help highly appreciated.

Thanks a lot in advance

Link to comment
Share on other sites

3 hours ago, Pantu said:

event.offsetmask(0x281C, 1,"UB","Batteryswitch")  --- bit 0

Offset 281C is 4 bytes, not an unsigned byte - and certainly not just 1 bit. Try with
    event.offset(0x281C, "UD","Batteryswitch")

Also, are you sure the lvar exists? If not, as the documentation on the ipc.writeLvar function says says: If the variable is not currently available, nothing happens

If not sure, just add a call to ipc.createLvar before the event.offset call.

John

 

Link to comment
Share on other sites

Hi John,

thank you very much for prompt reply. Tried your proposed changes, but unfortunately didn´t work.

I thought that the first line of my script "local Battery_on = {}" would have created a local variable, which could be used for my task and hence the Lvar would exist and be usable by external applications.  That thinking is obviously wrong.

If however I take a Lvar from a plane for instance, my script works.

Will have to look for unused Lvars of P3D and try to solve my problem. Don´t know which other way would let me generate Lvars, which could be accessed by Lorbys Axis and ohs.

Best regards

Pete

 

 

Link to comment
Share on other sites

22 minutes ago, Pantu said:

I thought that the first line of my script "local Battery_on = {}" would have created a local variable, which could be used for my task and hence the Lvar would exist and be usable by external applications.  That thinking is obviously wrong.

A local lua variable is not an lvar. An lvar is a local panel variable and lives with the aircraft model.

24 minutes ago, Pantu said:

Will have to look for unused Lvars of P3D and try to solve my problem. Don´t know which other way would let me generate Lvars, which could be accessed by Lorbys Axis and ohs.

As I said, you can use the ipc.createLvar function to create an lvar,

Cheers,

John

Link to comment
Share on other sites

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.