Jump to content
The simFlight Network Forums

Question Lua


Recommended Posts

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 = 1
1 Beacon = 2
2 Landing = 4
3 Taxi = 8
4 Strobes = 16
5 Instruments = 32
6 Recognition = 64
7 Wing = 128
8 Logo = 256
9 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" then

ipc.display ("Please wait, switching off lights!")

ipc.sleep(400)

-- NAV Lights OFF
NLI = logic.And(ipc.readUW(0x0D0C), 0x1)
if NLI ~= 0 then
ipc.control(66379)
end
ipc.sleep(1000)
-- Beacon Lights OFF
BLI = logic.And(ipc.readUW(0x0D0C), 0x2)
if BLI ~= 0 then
ipc.control(66239)
end
ipc.sleep(1000)
-- Landing Lights OFF
LLI = logic.And(ipc.readUW(0x0D0C), 0x4)
if LLI ~= 0 then
ipc.control(65751)
end
ipc.sleep(1000)

-- Taxi Lights OFF
TLI = logic.And(ipc.readUW(0x0D0C), 0x8)
if TLI ~= 0 then
ipc.control(66240)
end
ipc.sleep(1000)
-- Strobe Lights OFF
SLI = logic.And(ipc.readUW(0x0D0C), 0x16)
if SLI ~= 0 then
ipc.control(65560)
end
ipc.sleep(1000)

-- Panel Lights OFF
PLI = logic.And(ipc.readUW(0x0D0C), 0x32)
if PLI ~= 0 then
ipc.control(65750)
end
ipc.sleep(1000)

-- Recon Lights OFF
RLI = logic.And(ipc.readUW(0x0D0C), 0x64)
if RLI ~= 0 then
ipc.control(66377)
end
ipc.sleep(1000)
-- Wing Lights OFF
WING = logic.And(ipc.readUW(0x0D0C), 0x128)
if WING ~= 0 then
ipc.control(66378)
end
ipc.sleep(1000)
-- LOGO Lights OFF
LOG = logic.And(ipc.readUW(0x0D0C), 0x256)
if LOG ~= 0 then
ipc.control(66376)
end
ipc.sleep(1000)
-- Cabin Lights OFF
CLI = logic.And(ipc.readUW(0x0D0C), 0x512)
if CLI ~= 0 then
ipc.control(66579)
end
ipc.sleep(1000)

ipc.display("All lights switched off!\n Thanks for your patience, Captain!")
ipc.sleep(2500)
ipc.display ("")

elseif questvar ~= "y" then
ipc.display("Ok, was just a question, Sir!\nHave a nice day...")
ipc.sleep(3000)
end

ipc.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?

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.