February 24, 20179 yr Hi. New to Lua and programming in general, am I right in assuming that the function name can be anything I choose that is descriptive of its use? also I am trying to figure out why my code below wont work, nothing happens when I programme a switch on my X-55 with it. I used the LInda Tracer to find the Lvar relevant to opening the cockpit side door on the A2A Spitfire, and (after un-pausing FSX-S) the door opens by a command sent from the Linda Tracer "Set Value" Toggle (Shift+Ctrl+Alt+F10). Any help much appreciated. Linda 2.9.2 (487) Module: - A2A Spitfire (User) FSX-Steam Registered FSUIPC 4.9.6.2 Windows 10 (1607 - Build 14393.693) -- %% Side Door function SPIT_Side_Door_Open () LVarSet = "CockpitSideDoor" ipc.writeLvar(LVarSet, 1) end function SPIT_Side_Door_Close () LVarSet = "CockpitSideDoor" ipc.writeLvar(LVarSet, 0) end -- ## ############### OR put in a simpler way (I think?) -- %% Side Door function SPIT_Side_Door_Open () ipc.writeLvar(CockpitSideDoor, 1) end function SPIT_Side_Door_Close () ipc.writeLvar(CockpitSideDoor, 0) end -- ## ############### Many Thanks Roger All The Best Roger
February 25, 20179 yr Hi Roger A LUA function name can be anything you choose but, like all functions and variables, is case sensitive. There is a convention that the function should start with 3-4 characters referring the aircraft (ie. SPIT_). The suffix should be standardised to _on, _off, _open, _close, _up, _down, _inc, _dec, _toggle and _show. After writing/editing a function, you need to save it and then reload the changes by clicking on 'Reload LUA Engine' on the LINDA GUI Settings page. All changes in assignments to MCP Combo or Joysticks also require you to click 'Reload LUA Engine'. You have made a good start with your LUA code for the Spitfire pilot's side door. The side door will not open if the canopy is closed. As you have probably discovered there is no Lvar for the canopy. This has to be done by the FSX control 66389 which toggles the exit and you need to check the FSUIPC offset 3367 for the exit position. My rework of your code is: -- ## Cockpit Canopy and Door ##################################### -- $$ Canopy function SPIT_Canopy_open () pos = ipc.readUB(0x3367) -- get exit position if pos == 0 then ipc.control(66389,0) -- toggle exit/canopy ipc.sleep(4000) end SPIT_Canopy_show() end function SPIT_Canopy_close () LVarSet = 'CockpitSideDoor' pos = ipc.readUB(0x3367) if pos == 1 and ipc.readLvar(LVarSet) == 0 then ipc.control(66389,0) ipc.sleep(4000) end SPIT_Canopy_show() end function SPIT_Canopy_toggle () LVarSet = 'CockpitSideDoor' pos = ipc.readUB(0x3367) if ipc.readLvar(LVarSet) == 0 then if pos == 1 then SPIT_Canopy_close () else SPIT_Canopy_open () end else SPIT_Canopy_show() end end function SPIT_Canopy_closeAll () SPIT_Door_close () SPIT_Canopy_close () end function SPIT_Canopy_show () pos = ipc.readUB(0x3367) if pos == 0 then val = 'shut' else val = 'open' end if _MCP1() then DspShow("Cnpy", val) elseif _MCP2() or _MCP2a() then DspMed1("Canopy") DspMed2(val) end end -- $$ Cockpit Side Door function SPIT_Door_open () LVarSet = 'CockpitSideDoor' val = ipc.readLvar(LVarSet) if val == 0 then ipc.writeLvar(LVarSet, 1) ipc.sleep(3000) end SPIT_Door_show() end function SPIT_Door_close () LVarSet = 'CockpitSideDoor' val = ipc.readLvar(LVarSet) if val == 1 then ipc.writeLvar(LVarSet, 0) ipc.sleep(3000) end SPIT_Door_show () end function SPIT_Door_toggle () LVarSet = 'CockpitSideDoor' if ipc.readLvar(LVarSet) == 0 then SPIT_Door_open () else SPIT_Door_close () end end function SPIT_Door_show () LVarSet = 'CockpitSideDoor' if ipc.readLvar(LVarSet) == 0 then val = "clos" else val = "open" end if _MCP1() then DspShow("Door", val) elseif _MCP2() or _MCP2a() then DspMed1("Door") DspMed2(val) end end This will be included in the updated A2A Spitfire module. Andrew Gransden Scotland, UK LINDA Support/Developer - VATSIM and BAVirtual - Airbus Flyer i7 1TB SSD GTX980 - FSX/P3D - Aerosoft Airbus A318/A319/A320/A321 - FS2Crew
February 28, 20179 yr Author Hi Scotflieger. Many thanks, now I can see exactly what's going on, re the convention and IPC offsets etc, many thanks for getting back with this, you have helped me understand a great deal in a short space of time, my Spitfire will never be the same old same old again, Ive got Lua and also developing imagination! ATB Rog All The Best Roger
Archived
This topic is now archived and is closed to further replies.