Jump to content
The simFlight Network Forums

Unable to click cockpit buttons after FSUIPC LUA script action


Recommended Posts

Hello,

I am using FSUIPC6 on P3D v4.5, and quite often use LUA scripts to control my buttons - especially for functionality where I want to be able to do stuff like notifications or deal with two way buttons on my controllers.

I'm using the Thrustmaster Hotas Warthog (throttle and stick) and the Honeycomb Alpha Yoke. Those are the only USB game controllers attached to my system.

I'll show you a sample from one of my scripts:

-- I have these in a separate file (pmdg_777_offsets.lua)
THIRD_PARTY_EVENT_ID_MIN = 69632
EVT_OH_ELEC_GRD_PWR_PRIM_SWITCH	= THIRD_PARTY_EVENT_ID_MIN + 8
EVT_OH_ELEC_GRD_PWR_SEC_SWITCH = THIRD_PARTY_EVENT_ID_MIN + 7


-- My main script, called by button presses
-- External power
if ipcPARAM == 305 then
	-- Check if the ground power is off for each control, since button is a one-shot.
	if ipc.readSB(0x644C) == 1 then ipc.control(EVT_OH_ELEC_GRD_PWR_PRIM_SWITCH,1) end
	if ipc.readSB(0x644B) == 1 then ipc.control(EVT_OH_ELEC_GRD_PWR_SEC_SWITCH,1) end
end

if ipcPARAM == 306 then
  -- Check if the ground power is on for each control, since button is a one-shot.
	if ipc.readSB(0x644A) == 1 then ipc.control(EVT_OH_ELEC_GRD_PWR_PRIM_SWITCH,1) end
	if ipc.readSB(0x6449) == 1 then ipc.control(EVT_OH_ELEC_GRD_PWR_SEC_SWITCH,1) end
end

-- Button assignments on the Honeycomb Yoke
39=PD,16,CL41:R,305 	-{Lua PMDG 777}-
40=PD,17,CL41:R,306 	-{Lua PMDG 777}-

Quite often when I am running scripts like this, I lose "focus" in the simulator where I have to click outside the sim and back again for anything to register, sometimes multiple times. This is not exclusive to PMDG aircraft, I use it on the RealAir Turbine Duke and the Milviz King Air 350i, and have the same issue.

If I alt tab to a program and press escape, it is as if P3D has focus still, and escape brings up the "end scenario" screen, but no switches or in simulator buttons are working.

Any idea why this might be?

Link to comment
Share on other sites

2 hours ago, Henrik Bergvin said:

Quite often when I am running scripts like this, I lose "focus" in the simulator where I have to click outside the sim and back again for anything to register, sometimes multiple times. This is not exclusive to PMDG aircraft, I use it on the RealAir Turbine Duke and the Milviz King Air 350i, and have the same issue.

Are you using custom controls on those other aircraft too? 

I cannot see any way FSUIPC can cause mouse/keyboard focus to be lost using a script which merely sends controls to the Sim. It would act exactly as if the button were assigned to those controls.

Instead of the Lua script you show above you could have done exactly the same with direct assignments, so:

39=B644C=1 PD,16,69640,1
40=B644B=1 PD,16,69639,1
41=B644A=1 PD,17,69640,1
42=B6449=1 PD,17,69639,1

Can you see if the same happens with such assignments instead of using your Lua? The action as far as the sim is concerned is identical.

One other question: you say you have those EVT names declared in a file called "pmdg_777_offsets.lua", with the action carried out in "PMDG 777.lua". If this is correct then those event values must have been set in the Global lua, using ipc.set and retrieved using ipc.get. Are those lines in the Lua but simply missing in your post?

Finally, I don't have any fancy aircraft to test with. Can you make these problems happen with any default aircraft?

Pete

 

Link to comment
Share on other sites

I am using custom controls like these in those aircraft too, and I wasn't aware I could check offset statuses with direct assignemts - I'll have to give that a try and see if it can work.

The event names are declared and imported usin the default LUA way:

require "pmdg_777_offsets"

I have it for the PMDG birds because of the sheer number of controls, and I like names instead of number, and they work, just sometimes it locks up the clickability for some reason. I have as of yet not managed to find a specific culprit...

I've attached the two lua files I use for the 747, as well as my profile, maybe you can see something in it. Also, i should mention that i have UseProfiles=Files set in FSUIPC6.ini.

As for default aircraft, I haven't seen the need to do any form of LUA scripting for those, since they're so basic I don't really touch them at all.. 

PMDG 747.lua pmdg_747_offsets.lua 747.ini FSUIPC6.ini

Link to comment
Share on other sites

2 hours ago, Henrik Bergvin said:

I wasn't aware I could check offset statuses with direct assignemts - I'll have to give that a try and see if it can work.

Yes -- one of the forms of conditional assignments as described in the Advanced User's guide (page 24 I think). And my idea was to try to narrow it down -- determining whether it was related to the Lua plug-in method, or somehow related to those custom controls.

2 hours ago, Henrik Bergvin said:

As for default aircraft, I haven't seen the need to do any form of LUA scripting for those, since they're so basic I don't really touch them at all.

Well, we need to be able to reproduce your findings to work out what is going on. Nothing in what you've said you are doing involves any sort of focus change being made by FSUIPC or its Lua interpreter. They are just simple sending of controls to SimConnect for passign on to the add-on aircraft. 

So if you can make it happen, without going overboard with scripting, for one or other of the default aircraft, that would make some basic debugging possible. Else we'd need to ascribe it to something the PMDG coding is doing. But the first thing to help would be trying with more direct means than the Lua scripting.

Pete

 

 

 

Link to comment
Share on other sites

7 hours ago, Pete Dowson said:

So if you can make it happen, without going overboard with scripting, for one or other of the default aircraft, that would make some basic debugging possible. Else we'd need to ascribe it to something the PMDG coding is doing. But the first thing to help would be trying with more direct means than the Lua scripting.

Alright, I will see if I have time to do some tests today on one of the default aircraft 🙂

Link to comment
Share on other sites

50 minutes ago, Pete Dowson said:

Thank you. And please also try those alternative assignments I provided earlier for the PMDG 777.

Pete

 

I should mention that I am currently performing a flight in the 747, and have not had it happen at all. Only difference from my previous attempts were that I have installed the binding utility (and, I guess, driver package) for the Honeycomb Yoke. The yoke has more buttons than windows can detect (35) and the utility exposes those to the sim. I don't have anything bound to the last few buttons, but this *might* have been the issue.

I'll test your methods still, and let you know if they work out.

Link to comment
Share on other sites

On 8/11/2020 at 12:11 PM, Pete Dowson said:

Thank you. And please also try those alternative assignments I provided earlier for the PMDG 777.

Pete

 

It seems that using that method is a little better, I haven't had any issues with focus after trying those.

As for Lua scripts, is it better to call scripts using "Lua ScriptName" and a param, or do you recommend using the param event and passing LuaValue? I imagine events are queued and read one by one, so if two fire rapidly the script will run for the second once it is done with the first?

Link to comment
Share on other sites

13 minutes ago, Henrik Bergvin said:

I imagine events are queued and read one by one, so if two fire rapidly the script will run for the second once it is done with the first?

No, not for the same event type, only for different ones. Otherwise you get problems with backlogs catching up when you don't really want it.

On the first question:

14 minutes ago, Henrik Bergvin said:

As for Lua scripts, is it better to call scripts using "Lua ScriptName" and a param, or do you recommend using the param event and passing LuaValue?

The latter case is more efficient as the plug-in remains compiled and resident (you'd have to preload it, probably by [Auto] or a call in ipcReady.lua). But that's only really significant for frequently used actions.

For plug-ins being loaded each time you are really better off with smaller separate ones rather than very large ones proceeing one parameter then unloading. Of course there's a crossover point somewhere between the extremes. Horses for courses.

Pete

 

Link to comment
Share on other sites

28 minutes ago, Pete Dowson said:

No, not for the same event type, only for different ones

 

29 minutes ago, Pete Dowson said:

For plug-ins being loaded each time you are really better off with smaller separate ones rather than very large ones proceeing one parameter then unloading.

Understood. I do find using LuaValue a bit faster than Lua for param based scripts, so I'll stick to that in the future. I'll bind a push button to kill and restart the script for testing purposes.

 

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.