Jump to content
The simFlight Network Forums

Recommended Posts

Posted

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.

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

Posted
Quote

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

You're using "UB" which is 1 byte. Offset 0x281C is 4 bytes. So you're only testing the first byte. This will always be 0 because the entire 4-byte offset only stores 0 and 1. The actual bit you want to test is in offset 0x281F.

You can with target that byte:

event.offsetmask(0x281F, 1,"UB","Batteryswitch")

or tell LUA read the full 4 bytes from the original offset with "UD" (unsigned double word)

event.offsetmask(0x281C, 1,"UD","Batteryswitch")

You don't really need to test the individual bit as only one bit is ever flipped - the entire offset value can only be 0 or 1.

So you could also use the plain event.offset function like this and test the entire value (0 or 1):

event.offset(0x281C,"UD","Batteryswitch")

Paul

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.