flying_bob Posted July 30, 2012 Report Posted July 30, 2012 Now I have searched a lot and found some articles on how to Get the "lights" offsets to read that and then to get the Lua to change the settings I have one questions on Lights offset. from google I found the following http://forum.simflig...tch-setup-help/ this gave me soem info and explained how the lights work, so this is what I got. use 0D0C and the corresponding bit value (sorry I dont know if I use right termonology) 0D0C 2 Lights, a switch for each one (bits from lo to hi):0 Navigation = 11 Beacon = 22 Landing = 43 Taxi = 84 Strobes = 165 Instruments = 326 Recognition = 647 Wing = 1288 Logo = 2569 Cabin = 512[/CODE]here is my "lights section" lua[CODE]ipc.sleep(100)ipc.display("Lights Sequence initiated...")ipc.sleep(2000)questvar = ipc.ask("Captain, do you want to go set off all lights? (y / n)")if questvar == "y" thenipc.display ("Please wait, switching off lights!")ipc.sleep(400)-- NAV Lights OFFNLI = logic.And(ipc.readUW(0x0D0C), 0x1)if NLI ~= 0 thenipc.control(66379)endipc.sleep(1000)-- Beacon Lights OFFBLI = logic.And(ipc.readUW(0x0D0C), 0x2)if BLI ~= 0 thenipc.control(66239)endipc.sleep(1000)-- Landing Lights OFFLLI = logic.And(ipc.readUW(0x0D0C), 0x4)if LLI ~= 0 thenipc.control(65751)endipc.sleep(1000)-- Taxi Lights OFFTLI = logic.And(ipc.readUW(0x0D0C), 0x8)if TLI ~= 0 thenipc.control(66240)endipc.sleep(1000)-- Strobe Lights OFFSLI = logic.And(ipc.readUW(0x0D0C), 0x16)if SLI ~= 0 thenipc.control(65560)endipc.sleep(1000)-- Panel Lights OFFPLI = logic.And(ipc.readUW(0x0D0C), 0x32)if PLI ~= 0 thenipc.control(65750)endipc.sleep(1000)-- Recon Lights OFFRLI = logic.And(ipc.readUW(0x0D0C), 0x64)if RLI ~= 0 thenipc.control(66377)endipc.sleep(1000)-- Wing Lights OFFWING = logic.And(ipc.readUW(0x0D0C), 0x128)if WING ~= 0 thenipc.control(66378)endipc.sleep(1000)-- LOGO Lights OFFLOG = logic.And(ipc.readUW(0x0D0C), 0x256)if LOG ~= 0 thenipc.control(66376)endipc.sleep(1000)-- Cabin Lights OFFCLI = logic.And(ipc.readUW(0x0D0C), 0x512)if CLI ~= 0 thenipc.control(66579)endipc.sleep(1000)ipc.display("All lights switched off!\n Thanks for your patience, Captain!")ipc.sleep(2500)ipc.display ("")elseif questvar ~= "y" thenipc.display("Ok, was just a question, Sir!\nHave a nice day...")ipc.sleep(3000)endipc.display("")[/CODE]my question is that the last 3 lights (wing, logo, cabin) do not work so elegantly. If they ON, and I run the script, then all lights is being switched off except the cabin lights. If I then run the script again then the cabin lights is switched OFF, but logo lights is switched ON again. according to me if a light is OFF, then just nothing must happen.Can anyone maybe spot my mistake or guide me why the last 3 lights do not work properly. The only thing that is trhe same between them is that the "offsett" is more then 2 characters (124, 256 and 512). Could it maybe have something to do with that, as all thos 1 to 64 all seem to work correctly?
Pete Dowson Posted July 30, 2012 Report Posted July 30, 2012 here is my "lights section" lua First comment: You are reading offset 0D0C, which is not only the state of the lights, but also the control for the lights, yet you are then using "ipc.control" to send individual FS controls. All you need to do, and much more simply, is write to 0D0C with the sum of the values representing the lights you want ON. If you want them all off, just do this: ipc.writeUW(0x0D0C, 0) 0 has no bits set and therefore turns all lights off. No need to read 0D0C at all if you don't want to know if any lights are on To switch lights ON, just add together the values you have for the bits, and do ipc.setbitsUW(0x0D0C, N) where N is the sum (e.g. 16 + 128 for Strobes and Wind lights ON). Likewise use ipc.clearbitsUW to turn sleected lights off, or ipc.togglebitsUW to toggle on/off. Second comment. in all the lines like this the last parameter is wrong and is the reason your program doesn't work: SLI = logic.And(ipc.readUW(0x0D0C), 0x16) All the values you have for the bits in 0D0C are in DECIMAL. That's why they double each time for each successive bit (1, 2, 4, 8, 16, etc is a DECIMAL progression). So you must NOT precede it with "0x" which tells the computer you mean HEXADECIMAL! Your "0x16" is actually decimal 22 (1 x 16 + 6). So the above line would be SLI = logic.And(ipc.readUW(0x0D0C), 16) Please see the FAQ subforum thread about bits and numbers. Finally, please note that the only official reference for offsets is the offset lists provided in the FSUIPC SDK. Regards Pete
flying_bob Posted July 30, 2012 Author Report Posted July 30, 2012 Thank you kindly. I will sit down tonight and properly work through this answer. Sorry I am a bit of a pleb when it comes to writing code. I appreciate the extensive answer and from this I am sure I will be now able to get this sorted out.
Pete Dowson Posted July 30, 2012 Report Posted July 30, 2012 I appreciate the extensive answer and from this I am sure I will be now able to get this sorted out. Not much to sort out. I gave you the one line you need to switch all the lights out. Juyst replace all of your code between this ipc.display ("Please wait, switching off lights!")ipc.sleep(400) [/CODE]and this[CODE]ipc.sleep(1000)ipc.display("All lights switched off!\n Thanks for your patience, Captain!")[/CODE]by:[CODE]ipc.writeUW(0x0d0c, 0)[/CODE]or do you actually want them all going off one at a time with one second intervals? If so, just replace each group like this:[CODE]LOG = logic.And(ipc.readUW(0x0D0C), 0x256)if LOG ~= 0 then ipc.control(66376)end[/CODE]by this:[CODE]ipc.clearbits(0x0d0c, 256)[/CODE]with the "256" of course replaced by the correct bit value.Pete
flying_bob Posted July 30, 2012 Author Report Posted July 30, 2012 Ahhh thanks again Pete I think I now got the hang of this.. Been adding over 32 other switches etc and all working great..! Will post the full Cold and dark script here when I am done. Thanks for willingness to share your knowledge with us plebs and for the wonderfull work you do to make our life easier and to let us enjoy our sim.
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