Jump to content
The simFlight Network Forums

Short freeze on button press


Recommended Posts

Hi,

I am using regisitered FSUIPC 5.15 with p3d 4.4 to control several custom functions in aerosofts F-14X using the lua script provided with that aircraft. However, when I depress a button on my joystick that is associated with a lua command, the sim freezes for about half a second. This happens on both my VPC stick and WH throttle. Besides the F-14X I am using ORBX FTX Global and NA Landclass and VRS Tacpack. This also happens in FSX:SE with FSUIPC4 und the same conditions. I already tried adding the F-14 lua script to the autoload function but this didn't help. Any ideas are much appreciated. Ini and Log file are attached.

FSUIPC5.log

FSUIPC5.ini

Edited by sLYFa
Link to comment
Share on other sites

I am unfortunetly unable to post it as I am only allowed to upload 10kb. But here is an excerpt:

 

--------------------------------------------

---- Variables
--------------------------------------------
    Sweep_R1    = "L:tomcat_bomb_mode"
    Sweep_R2    = "L:tomcat_bomb_switch"
    Man_Sweep    = "L:tomcat_sweep_mode"
    Sweep_Cover    = "L:tomcat_wingsweep_cover"
    Over_Sweep     = "L:Sweep_Oversweep_flag"
    Emerg_Auto    = "L:Over_to_Auto"

--------------------------------------------
---- Scripts
--------------------------------------------


-- Sweep Rocker to Auto Mode
if ipcPARAM == 1 then
    ipc.writeLvar(Sweep_R1, 0)
    ipc.writeLvar(Sweep_R2, 0)    
end
-- Sweep Rocker to Bomb Mode
if ipcPARAM == 2 then
    ipc.writeLvar(Sweep_R1, 2)
    ipc.writeLvar(Sweep_R2, 2)    
end
-- Sweep Rocker to Manual FWD
if ipcPARAM == 3 then
    ipc.writeLvar(Man_Sweep, 1)
    ipc.writeLvar(Sweep_R2, 1)    
end
-- Sweep Rocker to Manual AFT
if ipcPARAM == 4 then
    ipc.writeLvar(Man_Sweep, -1)
    ipc.writeLvar(Sweep_R2, 1)    
end
-- Sweep Rocker to Center
if ipcPARAM == 5 then
    ipc.writeLvar(Man_Sweep, 0)
    ipc.writeLvar(Sweep_R2, 1)    
end
-- Emergency Sweep Cover Toggle
if ipcPARAM == 6 then
    tog = 0
    SCov = ipc.readLvar(Sweep_Cover)
    if SCov == 0 then
        tog = 1
    end
    ipc.writeLvar(Sweep_Cover, tog)    
end
-- Oversweep Toggle
if ipcPARAM == 7 then
    tog = 0
    OSw = ipc.readLvar(Over_Sweep)
    if OSw == 0 then
        tog = 1
    end
    ipc.writeLvar(Over_Sweep, tog)    
end

 

 

Link to comment
Share on other sites

It sure does look like a run once, self killing lua. (need full code)
Meaning it launches each time a button is pressed, then killing itself. 

Loading the lua then iterating through all the if/elses to find the correct one, doing the command then killing itself will put a tax on the sim.
A more efficient way would be to rewrite the code using functions and using an event listener such as event.flag then have the lua be auto started (using profiles) on the F-14 aircraft load.
Re-assigning buttons or keys would not be that difficult either - changing from "Lua <lua name>" to "LuaToggle <lua name>" using the same parameters. (even easier via editing the FSUIPC.ini)
Can almost guarantee that a rewrite of the code (based on the provided above) to something similar to the following should fix it up nicely - 

local SCov = 0
local OSw = 0
local tog = 0

-- Sweep Rocker to Auto Mode
function P1(flag)
    ipc.writeLvar(Sweep_R1, 0)
    ipc.writeLvar(Sweep_R2, 0)    
end
-- Sweep Rocker to Bomb Mode
function P2(flag)
    ipc.writeLvar(Sweep_R1, 2)
    ipc.writeLvar(Sweep_R2, 2)    
end
-- Sweep Rocker to Manual FWD
function P3(flag)
    ipc.writeLvar(Man_Sweep, 1)
    ipc.writeLvar(Sweep_R2, 1)    
end
-- Sweep Rocker to Manual AFT
function P4(flag)
    ipc.writeLvar(Man_Sweep, -1)
    ipc.writeLvar(Sweep_R2, 1)    
end
-- Sweep Rocker to Center
function P5(flag)
    ipc.writeLvar(Man_Sweep, 0)
    ipc.writeLvar(Sweep_R2, 1)    
end
-- Emergency Sweep Cover Toggle
function P6(flag)
    tog = 0
    SCov = ipc.readLvar(Sweep_Cover)
    if SCov == 0 then
        tog = 1
    end
    ipc.writeLvar(Sweep_Cover, tog)    
end
-- Oversweep Toggle
function P7(flag)
    tog = 0
    OSw = ipc.readLvar(Over_Sweep)
    if OSw == 0 then
        tog = 1
    end
    ipc.writeLvar(Over_Sweep, tog)    
end

event.flag(1, "P1")
event.flag(2, "P2")
event.flag(3, "P3")
event.flag(4, "P4")
event.flag(5, "P5")
event.flag(6, "P6")
event.flag(7, "P7")

EDIT - Looking at your FSUIPC.ini It looks like my assumptions are indeed fact - a run once, self killing lua with possibly 200+ commands!?! That is a lot of iterations to run through each time an assigned button is pressed.
Also below is an example of how easy it could be by hand editing the .ini after the lua code change, changes in bold red.

Ex.. 
1=P0,17,CL1:R,0     -{Lua Aerosoft_F14AB}-
would become
1=P0,17,CL1:T,0     -{Lua Aerosoft_F14AB}-
and on and on for the rest of the F-14 assignments.

Roman

Link to comment
Share on other sites

As spokes2112 says, this is not an efficient way run such a large lua file. Each time you call this, it has to create the thread and compile the lua script before it runs. It would be more efficient to have the lua auto-started (and compiled!) and activated on an event flag. You can also consider breaking the script down into multiple smaller files.

Cheers,

John

 

Link to comment
Share on other sites

John and/or Pete,

As a self taught lua scripter I was wondering if my example above still isn't very efficient.
Was thinking that creating ~200 separate 'event.flag' listeners isn't a good idea.
Based on that premise I did some experimenting and created the following using a global 'event.flag' listener.
It seems very efficient for use with many functions.
Works fine but the only drawback seen is that FSUIPC logging does not recognize the ending function because of the use (?) of the global namespace to call it.
No big deal, or is it?
Thoughts? and/or tips?
Currently have no use for the example but probably will in the near future so keeping it in the back pocket for now.

Pete - Congrats on your upcoming retirement! Cannot Thank You enough for your contributions to the flight sim community!
More so, I have learned lua, VB.net, and a little bit of C# (thanks Paul Henty) only because of the existence of FSUIPC..  
That is worth a million Thank-You's in of itself.   

Happy New Year! 
Roman 

-- Landing Lights, param = 1
function funcNum1()
	ipc.control(65751)   
end

-- Nav Lights, param = 2
function funcNum2()
	ipc.control(66379)   
end

-- Parking Brake, param = 3
function funcNum3()
	ipc.control(65752)   
end

-- Flaps Up, param = 4
function funcNum4()
	ipc.control(65595)    
end

-- Flaps Down, param = 5
function funcNum5()
	ipc.control(65603)   
end

-- Select proper function above in global namespace
-- This function called from funcProtect (below)
function funcSelect(flag)
	_G['funcNum' .. flag]()
end

-- Call "funcSelect" (above) in protected mode (below)
-- If FSUIPC parameter does not call a function
-- Show lua window giving bad parameter number - keep lua running
function funcProtect(flag)
	if  pcall(funcSelect, flag) == false then
		ipc.display(flag .. ' is not a valid parameter for this lua!', 2)
	end
end

-- Using "LuaToggle"
event.flag("funcProtect")

 

Link to comment
Share on other sites

Thank you for your feedback!

On 12/28/2018 at 11:42 AM, spokes2112 said:

a run once, self killing lua with possibly 200+ commands!?! That is a lot of iterations to run through each time an assigned button is pressed.

Thats what I was thinking too. The script is quite large indeed (1000+ lines). However, I tried cropping the script to only four commands but the result was the same.

On 12/29/2018 at 5:26 PM, John Dowson said:

It would be more efficient to have the lua auto-started (and compiled!) and activated on an event flag.

I am not sure how to do that. I believed that adding the lua to the autostart section in the .ini would do that. But again, this doesnt seem to make any difference.

I am going to rewrite the script according to spokes´ suggestion and see if that helps.

Link to comment
Share on other sites

5 hours ago, sLYFa said:

am not sure how to do that. I believed that adding the lua to the autostart section in the .ini would do that. But again, this doesnt seem to make any difference.

The lua itself is still self - killing so when autostarted it will just end. Needs to be re-written.

5 hours ago, sLYFa said:

However, I tried cropping the script to only four commands but the result was the same.

Most likely because it is still compiling on each start. 

An overview of what is needed:
1) A rewrite of the lua so it does not kill itself. The use of an event listener - event.flag("<function name>")  will accomplish this.
2) Use auto start in profiles, or, globally to test.
     [Auto]
     1=Lua <my F-14 lua name>
3) Use any of the following FSUIPC commands to initiate the already running lua.
     Do not use Lua <my F-14 lua name> as this will just restart it
     a) LuaToggle <my F-14 lua name>  <-- This will most likely be the one to use.
     b) LuaSet <my F-14 lua name>
     c) LuaClear <my F-14 lua name>

A friend sent me the lua from his AS F-14 package. Will be able to look closer and test now, he wants a rewrite too! 😉

Roman 

EDIT - Just looked at it.. It uses ipcParam instead so my notes above are invalid (in red). Will be able to get this much more efficient though.. 

 

Edited by spokes2112
Looked at code.. Assumptions changed
Link to comment
Share on other sites

Hi Roman,

I'm still quite new to lua myself, so I'll leave it to Pete to answer your questions when he returns. However, thought I'd mention that you can always use the 'event.button' (set of) functions instead to call the function on the button press without going through the FSUIPC assignment to toggle/set a flag.

Cheers,

John

Link to comment
Share on other sites

sLYFa,

Wow!
That original supplied lua was really a killer.
Not only did it self kill itself but when restarted on each command it initialized, at minimum, 75 variables. Only 2 are needed.
I rewrote it using all the commands. It does take quite a bit on the first load (using auto) to read and compile everything - about 10 seconds!
After that, while listening for commands, it just sits there. On a command it goes through about 6 lines, taking a millisecond or less. Seems to work well.

Overall the complete method & about 80% of the code was changed.
In my opinion it still lies in a grey area for redistribution since it was originally supplied as payware, and, I don't own it. 
If you would like to try it just PM me and I will send you the link. 

Roman

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.