Jump to content
The simFlight Network Forums

Recommended Posts

Hi Pete & John,

A Lua plug-in I set up for the A2A C172 contains the following function :
 

function C172_Door_Open_If_Closed()
    local doors
    doors = ipc.readUB(0x3367)
    if logic.And(doors,1) == 0    -- pilot door closed
    and ipc.readUB(0x0366) == 1    -- aircraft on ground
    then
        ipc.setbitsUB(0x3367, 1)
    end
--    doors = ipc.ask("Which door?\n1=Pilot\n2=Pax\n3=Both") -- 1 = pilot, 2 = passenger, 3 = both
--    if doors = 1 or doors = 2 or doors = 3 then    -- check input is valid
--        if ipc.readUB(0x0366) == 1        -- aircraft on ground
--        then
--            ipc.setbitsUB(0x3367, doors)
--        end
--    end
end

event.flag(54, "C172_Door_Open_If_Closed")

The active section works fine.  But I thought it would be handy to be able to select which door to open without having to edit the Lua script.  So I replaced the active section below the "local doors" line with the section marked as Remarks above.  Unfortunately no window to enter the door selection appears.  Debug did not show a syntax error so it must be my logic (or more likely, the lack of it).  Perhaps I cannot use a string as a mask to set a bit in offset 3367 and if so, how can I fix that ?  Can you help put me on the right track ?  Using FSUIPC 6.0.12 (registered) with P3DV4.5 HF3.  Thanks for any hints.

Regards,
Emile.

Link to post
Share on other sites
3 hours ago, Emile B. said:

Unfortunately no window to enter the door selection appears. 

No clue on this one. Perhaps the errors below fail the whole lua.

IIRC the ipc.ask() returns a string so you could do this 1 of 2 ways -
1) Put this line under ipc.ask() and change your comparison signs in the then following line from = to == &  you should be good the rest of the way :
doors = tonumber(doors)
-or-
2) Change the following 2 lines to first, test against a string & correct the comparison signs, and second, to convert to number for ipc.setbits
if doors == "1" or doors == "2" or doors == "3" then    -- check input is valid 
ipc.setbitsUB(0x3367, tonumber(doors))

Hope this helps,
Roman

  • Thanks 1
Link to post
Share on other sites
20 hours ago, spokes2112 said:

1) Put this line under ipc.ask() and change your comparison signs in the then following line from = to == &  you should be good the rest of the way :
doors = tonumber(doors)

Yes, that worked a treat !  Many thanks indeed !

Regards,
Emile.

Link to post
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...
×
×
  • 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.