Luis Hernández Posted May 4, 2020 Report Posted May 4, 2020 I'm trying to add a way to control the lights in the Aerosoft A320 for FSX-SE. If I do a single LUA control per light, with this code, it works: Taxi=ipc.readLvar("L:AB_TAXI_LT") if Taxi==nil or Taxi==0 then ipc.writeLvar("L:AB_TAXI_LT", 1) elseif Taxi==1 then ipc.writeLvar("L:AB_TAXI_LT", 2) else ipc.writeLvar("L:AB_TAXI_LT", 0) end return This code allows me to cycle the Taxi lights between 3 different conditions. If I assign a button in FSUIPC as LUA AS_A320 (that's the filename I used for it), it works as intended, but it will require a LUA file per each light. However, for simplicity (and a bit of OCD), I'd like to have 4 functions (taxi, landing, strobe and beacon lights) in a single LUA, and call them using functions and flags, the code woild change to this: function Lights_TAXI_toggle() Taxi=ipc.readLvar("L:AB_TAXI_LT") if Taxi==nil or Taxi==0 then ipc.writeLvar("L:AB_TAXI_LT", 1) elseif Taxi==1 then ipc.writeLvar("L:AB_TAXI_LT", 2) else ipc.writeLvar("L:AB_TAXI_LT", 0) end end event.flag(3, "Lights_TAXI_toggle") After this, I assign a button in FSUIPC as Lua Set, and in the parameter box, i enter 3. However, I can't make this switch work. Changing to Lua Toggle or adding a Lua Clear does not change the situation at all. What may I be doing wrong? Best regards, Luis
spokes2112 Posted May 5, 2020 Report Posted May 5, 2020 Luis, Not sure if this will cause it ( use lua logging ) but when using 2 parameters ( flag#, function name ) or just the necessary 1 parameter ( function name ), the flag number triggering event.flag gets passed to the function "Lights_TAXI_toggle". You have no variable name in the function for the value to get passed to. IE function-name(flag) Not really sure, but it could be the reason and may cause the lua to fail. Here's one other way: Use: LuaToggle <lua name> with parameters of 1 = taxi, 2 = landing, 3 = strobe, 4 = beacon function my_Lights(flag) if flag == 1 then -- do the taxi lights stuff here end if flag == 2 then -- do the landing lights stuff here end if flag == 3 then -- do the strobe lights stuff here end if flag == 4 then -- do the beacon lights stuff here end -- you could add more "if's" here for more on/off boolean type operations here, using different flag numbers end event.flag("my_Lights") Roman
Donovan Posted May 5, 2020 Report Posted May 5, 2020 In the same vein, with slightly different syntax is a similar workable method. (Flag set using LuaSet, param) --lights.lua function LightsControl(flag) if ipc.testflag(1) then --TaxiLights ipc.clearflag(1) Taxi=ipc.readLvar("L:AB_TAXI_LT") if Taxi==nil or Taxi==0 then ipc.writeLvar("L:AB_TAXI_LT", 1) elseif Taxi==1 then ipc.writeLvar("L:AB_TAXI_LT", 2) else ipc.writeLvar("L:AB_TAXI_LT", 0) end elseif ipc.testflag(2) then --Landing Lights ipc.clearflag(2) -- [Insert Desired Code] elseif ipc.testflag(3) then --Stobe Lights ipc.clearflag(3) -- [Insert Desired Code] elseif ipc.testflag(4) then --Beacon Lights ipc.clearflag(4) -- [Insert Desired Code] else end end event.flag("LightsControl") Best, Don
adrem Posted May 5, 2020 Report Posted May 5, 2020 @Luis Hernández Are you launching the script first? In your situation, I assume you'd want to auto-launch it when loading an AS Airbus. Auto-launching scripts is covered in the manual. Also, you definitely need to use LuaToggle here, otherwise it will only work once since you're not clearing the flag anywhere.
Luis Hernández Posted May 5, 2020 Author Report Posted May 5, 2020 12 hours ago, adrem said: Are you launching the script first? If you mean this, Adrem [Auto.AS_Airbus] 1=AS_A320 Yes, I had it auto-launched. I tried again with LuaToggle, but it didn't work. Also, using either Donovan and Roman's methods gave me the same result: nothing. There's something I must be doing wrong, but I can't find what may be.
adrem Posted May 5, 2020 Report Posted May 5, 2020 19 minutes ago, Luis Hernández said: Yes, I had it auto-launched But are you sure it's actually launching? Does it work when you launch it manually via a bind?
Pete Dowson Posted May 5, 2020 Report Posted May 5, 2020 On 5/4/2020 at 9:21 PM, Luis Hernández said: After this, I assign a button in FSUIPC as Lua Set, and in the parameter box, i enter 3. However, I can't make this switch work. Changing to Lua Toggle or adding a Lua Clear does not change the situation at all. What may I be doing wrong? Have you tried using any of the FSUIPC logging facilities to check? You can get a trace on what the Lua is doing and what button actions are occurring. There's a bug we've only just found whereby LuaKill, LuaSet/Toggle/Clear, and LuaValue don't work if yo are using a separate path for your Lua files. Could that be the case? A fix has been implemented and in included in FSUIPC6.0.6, now available. The fix for FSUIPC5 will be later. But I'm afraid one isn't currently planned for FSUIPC4. Otherwise a sight of your FSUIPC4.INI file, and such a log, would be useful if you can't figure it out from that. As already noted by others, unless you clear the flag using LuaSet on it again won't change it and so won't trigger an event. I also think you need to use LuaToggle, so it changes each time. Pete
Luis Hernández Posted May 6, 2020 Author Report Posted May 6, 2020 I've generated some logs. However, I can't see if the LUA was ever loaded, but I think it never did, actually. I tried logging with my current, non-working code version (see below) and the original one, as the one I described first in my first post. I'm attaching the 2 latest logs and my INI file. I can't see anything special, apart from the fact that somehow does not work. My full, non-working code: function AS_A320_lights(flag) -- Landing lights (retract/ext off/ext on) if ipc.testflag(1) then Landing=ipc.readLvar("L:Landlight_switch") if Landing==nil or Landing==0 then ipc.writeLvar("L:Landlight_switch", 2) else ipc.writeLvar("L:Landlight_switch", 0) end ipc.clearflag(1) end -- Strobe lights (off/auto/on) if ipc.testflag(2) then Strobe=ipc.readLvar("L:Strobe_light") if Strobe==nil or Strobe==0 then ipc.writeLvar("L:Strobe_light", 2) else ipc.writeLvar("L:Strobe_light", 0) end ipc.clearflag(2) end -- Taxi lights (off/taxi/takeoff) if ipc.testflag(3) then Taxi=ipc.readLvar("L:AB_TAXI_LT") if Taxi==nil or Taxi==0 then ipc.writeLvar("L:AB_TAXI_LT", 1) elseif Taxi==1 then ipc.writeLvar("L:AB_TAXI_LT", 2) else ipc.writeLvar("L:AB_TAXI_LT", 0) end ipc.clearflag(3) end -- Beacon lights (on/off) if ipc.testflag(4) then Beacon=ipc.readLvar("L:LIGHT_BEACON") if Beacon==nil or Beacon==0 then ipc.writeLvar("L:LIGHT_BEACON", 1) else ipc.writeLvar("L:LIGHT_BEACON", 0) end ipc.clearflag(4) end end event.flag("AS_A320_lights") FSUIPC4 - INI.txt Log with LUA only.txt Log with LUASet.txt
Pete Dowson Posted May 6, 2020 Report Posted May 6, 2020 Quote I can't see if the LUA was ever loaded, but I think it never did, actually. It is, as clearly shown in your logs (didn't you look?). You are starting the Lua plug-in by pressing a button allocated to run it: 715172 [Buttons] now profile-specific: 715172 2=P0,10,CL3:S,3 715172 3=P0,11,CL3:S,4 715172 4=P0,8,CL3:R,1 715172 5=P0,9,CL3:S,2 716922 Button changed: bRef=0, Joy=0, Btn=8, Pressed 716922 [Buttons.Airbus A319 Avianca HK-4553] 4=P0,8,CL3:R,1 716969 LUA.0: beginning "C:\Steam\steamapps\common\FSX\Modules\AS_A320.lua" Notice the button assignments you are using: they are specific to Airbus A319 Avianca HK-4553. 3 of them are for flags 2, 3 and 4, but you have no assignment for flag 1. You just kept restating the plug-in using button 8. The button you assigned to Set flag 1 is here: [Buttons.AS_Airbus] 2=P0,10,CL3:S,3 -{LuaSet AS_A320 (Flag 3)}- 3=P0,11,CL3:S,4 -{LuaSet AS_A320 (Flag 4)}-4=P0,8,CL3:S,1 -{LuaSet AS_A320 (Flag 1)}- 5=P0,9,CL3:S,2 -{LuaSet AS_A320 (Flag 2)}- Those only operate for the AS_Airbus profile, which you weren't using according to the logs. It appears you also tried to make the plug-in start automatically for that AS_Airbus profile: [Auto.AS_Airbus] 1=AS_A320 but that won't work because the entries for Auto are full control names, not simply filenames. You need 1=Lua AS_A320 just as you would select in the assignments. The Auto sections are to enavle ANY cotrols to be automatically executed, it isn't only for loading plug-ins. Pete
Luis Hernández Posted May 6, 2020 Author Report Posted May 6, 2020 12 hours ago, Pete Dowson said: It appears you also tried to make the plug-in start automatically for that AS_Airbus profile: [Auto.AS_Airbus] 1=AS_A320 but that won't work because the entries for Auto are full control names, not simply filenames. You need 1=Lua AS_A320 just as you would select in the assignments. That was the issue!!! I corrected this line in the INI file, and now my latest code works as intended. I would have never seen this error. Thank you very much, Pete!
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