EmileBax Posted August 5, 2013 Report Posted August 5, 2013 Hi Peter,Is there a Lua library function or other way with which I can test the status of one specific bit in a FSX offset ? I have looked through the FSUIPC document "FSUIPC Lua Library.pdf" as well as searched your forum and could not find what I wanted, though of course I may have overlooked something.Reason for asking : I have written a simple Lua plug-in which contains amongst others a function that writes ipc control 66239 to toggle the aircraft beacon on or off. The function is called by an event (toggle of a flag). I want execution of this function to be conditional upon the status of the beacon (i.e. bit 1 in offset 0D0C). With all other external aircraft lights off, 0D0C returns the values 0 and 2 for beacon off and on respectively, and my function works if I test for 0D0C=2. However the returned value of 0D0C for beacon on will not be =2 if other external lights are also on. That's why I would like to read the value of bit 1 (as well as a few other bits such as those for the strobe and landing lights).I only started working with Lua less than two years ago and at my age (60), learning new things doesn't come as easy as it used to so please bear with me if my question is a bit basic. Many thanks in advance for any hints, and for your invaluable creation FSUIPC. Regards,Emile.
Pete Dowson Posted August 5, 2013 Report Posted August 5, 2013 Is there a Lua library function or other way with which I can test the status of one specific bit in a FSX offset ? I have looked through the FSUIPC document "FSUIPC Lua Library.pdf" as well as searched your forum and could not find what I wanted, though of course I may have overlooked something. You simply read the byte or word or whatever and use the logic function And to test the bit. I want execution of this function to be conditional upon the status of the beacon (i.e. bit 1 in offset 0D0C). With all other external aircraft lights off, 0D0C returns the values 0 and 2 for beacon off and on respectively, and my function works if I test for 0D0C=2. However the returned value of 0D0C for beacon on will not be =2 if other external lights are also on. That's why I would like to read the value of bit 1 (as well as a few other bits such as those for the strobe and landing lights). So the test would be: lights = ipc.readUW(0x0D0C) if logic.And(lights,2) ~= 0 then ... end I only started working with Lua less than two years ago and at my age (60), learning new things doesn't come as easy as it used to so please bear with me if my question is a bit basic. I am 70 this month, but i'm always learning new things. It's what makes life interesting! ;-) Regards Pete
EmileBax Posted August 6, 2013 Author Report Posted August 6, 2013 Hi Peter, So the test would be: lights = ipc.readUW(0x0D0C) if logic.And(lights,2) ~= 0 then ... end Works like a charm ! In fact I've managed to build a little test function to help me understand the logic behind it but the main thing is that I can now do what I wanted to do. You are very right as far as keeping on learning, regardless of age, goes. If I lived close enough I'd treat you to a pint or two. But since I live about as far away from the UK as possible, a very big THANK YOU :grin: will have to do. Regards,Emile.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now