Jump to content
The simFlight Network Forums

even offset bits


Recommended Posts

Hi,

I tried to look it up in the docs, but I do not find it specifically mentioned if the

event.offset(0x5646, "UB", 2, "xxx")

syntax can be used for Lua or not.

I mean checking a specific bit in this case. The debugger doesn't give me an error if I use the format above.

Is it allowed? Is the syntax right for the first bit in this case?

thanks

Achoriham

Link to comment
Share on other sites

I tried to look it up in the docs, but I do not find it specifically mentioned if the

event.offset(0x5646, "UB", 2, "xxx") syntax can be used for Lua or not.

All the permissable syntax formats are documented, so you must assume that anything not included is ... not included. I can't very well list every possible syntax which is not implemented, now, can I? ;-)

.

I mean checking a specific bit in this case. The debugger doesn't give me an error if I use the format above

Debugger? That doesn't do any syntax checking, it is only a line execution tracing facility. The above syntax should give an error when the event occurs saying it cannot locate the function denoted by "2". The excess parameter "xxx" would be ignored. Lua in general doesn't care how many parameters you give, it just passes them on and lets the receiver use them if it wants to.

Is it allowed? Is the syntax right for the first bit in this case?

No and no. First bit from least significant end is bit 0 which has a value of 1 in masks. Number 2 is twice 1 so it's the next bit up, bit 1. Bit numbers and values are simply related by powers of 2, so 2^N is the value of bit N. Same as in decimal, decimal digit 2 is worth 10^2 or 100 (count 1 as bit 0, 10 as bit 1, etc). Please see the FAQ thread on bits and numbers.

Anyway, to do what you want to do you have to use

event.offset(0x5646, "UB", "xxx")

then in function xxx(offs, val) test your bit using

if logic.And(val, mask) ~= 0 then

...

end

where mask is your bit value, 1 for bit 0 or whatever.

If you just want to know when it changes


oldval = -1
function xxx(off, val)
newval = logic.And(val, mask)
if newval ~= oldval then
...
oldval = newval
end
end

[/CODE]

Regards

Pete

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • 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.