guenseli Posted October 31, 2014 Report Posted October 31, 2014 Hello Pete, a question after a long time again ;) I use the following LUA script to assign cowl flaps (in this case) to several addons: -- Assignments valid for all A2A Addons and Realair Duke -- rounds the integer function round(num) num = tonumber(num) if num == nil then return 0 end if num >= 0 then return math.floor(num+.5) else return math.ceil(num-.5) end end function round2 (num, idp) num = tonumber(num) if num == nil then return 0 end local mult = 10^(idp or 0) return math.floor(num * mult + 0.5) / mult end acftname = ipc.readSTR("3D00", 35) ------------------------------------------------------------- P51 -- Radiator lever if string.find(acftname,"P-51D",0,true) then var = round(((ipcPARAM+16384)/32768*10)/2) ipc.writeLvar("L:LandFlapsPos", var) ------------------------------------------------------------- Spitfire elseif string.find(acftname,"Spitfire",0,true) then var = round(((ipcPARAM+16384)/32768*10)/2) --ipc.display(var) --ipc.sleep(50) ipc.writeLvar("L:Eng1_RadiatorLeverPos", var) ------------------------------------------------------------- P40 elseif string.find(acftname,"P-40",0,true) then var = (ipcPARAM+16384)/32768*100 --ipc.display(var) --ipc.sleep(50) ipc.writeLvar("L:Eng1_RadiatorLeverPos", var) ------------------------------------------------------------- RealAir Duke elseif string.find(acftname,"RealAir Beech Duke Turbine",0,true) then var = (ipcPARAM+16384)/32768*100 --ipc.display(var) --ipc.sleep(50) if var < 20 then ipc.writeLvar("L:Duke_Cowl_Flaps_Switch_1", 0) ipc.writeLvar("L:Duke_Cowl_Flaps_Switch_2", 0) elseif var >= 20 and var <= 70 then ipc.writeLvar("L:Duke_Cowl_Flaps_Switch_1", 1) ipc.writeLvar("L:Duke_Cowl_Flaps_Switch_2", 1) elseif var > 70 then ipc.writeLvar("L:Duke_Cowl_Flaps_Switch_1", 2) ipc.writeLvar("L:Duke_Cowl_Flaps_Switch_2", 2) end ------------------------------------------------------------- C182 elseif string.find(acftname,"C182",0,true) then var = (ipcPARAM+16384)/32768*100 --ipc.display(var) --ipc.sleep(50) ipc.writeLvar("L:Eng1_CowlFlapsLever", var) end So far, they work as they should, however I have encountered now, that these scripts (or the assigning of these scripts) cause big stutters. From 40 to 50th down to 10 or 5 frames in unregular intervals. With unregular intervals I mean not exactly every second as example, but nearly every second - sometimes more, sometimes less. If the levers stay at zero, there's no problem. I have assigned that scripts via "send to FS as normal axis" and I use FSUIPC 4.937 in P3Dv2.4 Do you have any idea what is the issue here? Many thanks, Günter
Pete Dowson Posted November 1, 2014 Report Posted November 1, 2014 Do you have any idea what is the issue here? Only that possibly the loading, compiling and execution of such a complex script is sometimes taking longer than the interval between changes in the axis values. There are two things you can probably do about that. One is to compile the script (FSUIPC can load pre-compiled scripts as well as text ones). I think the compiler is called LUAC and should be available on the Lua website. the other is to increase the Delta on the axis assignments so it isn't called so frequently. An alternative, requiring a little change to the script, would be to make the script resident (loaded by an [Auto] parameter), and have it process the ipcPARAM on a polled basis -- i.e using a timer event. Then assign the axes to LuaValue instead of direct to the Lua script itself. I must admit i'm surprised cowl flap controls requite such a complex script! Pete
guenseli Posted November 1, 2014 Author Report Posted November 1, 2014 Many thanks for the advices, Pete. Will try both suggestions and see what works better Günter
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