Jump to content
The simFlight Network Forums

Is this Correct

Recommended Posts

Dear Mr Dowson,

I have written this small Lua, and allthough it does work, I would like to know if I did it in the correct way.

It would not be the first time I get something working in a completely wrong or too complicated way.......

This is supposed to handle GoFlight Led's when Aircraft doors are opened or closed, APU is started or stopped, APU generator is activated or de-activated.


function Doors(off, val)

if logic.And(val, 1) ==1 then --Opening Doors (Offset 3367/ size1/ read only)

gfd.SetLight(GFP8, 1, 0) --Door Led on


gfd.ClearLight(GFP8, 1, 0)



function ApuStart(off, val)

if logic.And(val, 99) >=99 then -- When RPM is at 99% or more (Offset 0B54/ size4/ read only)

gfd.SetLight(GFT8, 0, 0) --Apu Led on


gfd.ClearLight(GFT8, 0, 0)



function ApuGen (off,val)

if logic.And(val,1) ==1 then --When Generator is activated (Offset 0B52/ size1/read only)

gfd.SetLight(GFT8, 0, 1) --Gen Led on


gfd.ClearLight(GFT8, 0, 1)



event.offset(0x3367, "UB", "Doors") --Doors Check

event.offset(0x0B54, "FLT", "ApuStart") --Apu Starter

event.offset(0x0B52, "UB", "ApuGen") --Apu Generator Active?




Link to comment
Share on other sites

if logic.And(val, 99) >=99 then -- When RPM is at 99% or more (Offset 0B54/ size4/ read only)

All okay except for that line. The "AND" function logically ANDs two binary values -- in your case one is 99 (0x63 or binary 0110 0011). If the value was 100 (say), or x64, binary 0110 0100 then ANDing it with 0110 0011 gives 0110 0000 which is actually LESS than 99!

AND gives a 1 where both values contain a 1, else a 0, see:

0 1 1 0 0 0 1 1 = 99

0 1 1 0 0 1 0 0 = 100


0 1 1 0 0 0 0 0 = 96

You use logical functions to extract and testor toggle bits. But arithmetic values you just use values! i.e

if val >=99 then -- When RPM is at 99% or more (Offset 0B54/ size4/ read only)


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.

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.


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