Jump to content
The simFlight Network Forums

LUA script for axis is causing stutters


Recommended Posts

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

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • 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.