Jump to content
The simFlight Network Forums
Masterius

Can a button be programmed to run a .lua?

Recommended Posts

Can a button be programmed to run a .lua?

It appears that buttons can be programmed for keypresses, controls, and macros, but not a .lua. 

Share this post


Link to post
Share on other sites

Hi,

yes you can but the Lua file you want to start, stop or kill (...) needs to be in the FSUIPC folder location. You will then find it under Controls.

Did you actually search for Lua in controls?

In the pic you see I have a Lua file in the folder "DisplayFPS.lua" and those are all the possible assignable controls for that Lua file (as for any other).

image.png.d0ca61bd384b68e0bed62061567bf052.png

Thomas

Share this post


Link to post
Share on other sites
14 hours ago, Masterius said:

It appears that buttons can be programmed for keypresses, controls, and macros, but not a .lua. 

Starting/stopping luas are controls added by FSUIPC, as Thomas has shown you.

Share this post


Link to post
Share on other sites
15 hours ago, Thomas Richter said:

Did you actually search for Lua in controls?

Oddly enough, had I searched for Lua in controls, I highly doubt I would have asked this question.

Since I was going to be conditionally programming the .lua, and as you can't directly assign that through the GUI interface but are required to manually program that, I was trying to do so using the instructions found in pages 18 thru 28 of the FSUIPC4 for Advanced Users.pdf. The examples used there for control definitions are the typical Cxxxxx format, such as C65570. I'm familiar with that, and extensively use them in my scripts. I hadn't encountered the "CL" definition before, and since I was so focused on manually writing the script, it never occurred to me to use the GUI to get the script started. 

My bad.

Thank you for the answer.

 

Update: Having added the .lua as described, using the button does nothing. However, if I assign the .lua to the same button using LINDA it then runs. The buttons that aren't working are 14-17.

Here is the code: 

[Buttons.B-17]
0=RA,32,C65734,0     -{PAN_UP}-
1=RA,34,C65672,0     -{PAN_RIGHT}-
2=RA,36,C65735,0     -{PAN_DOWN}-
3=RA,38,C65671,0     -{PAN_LEFT}-
4=PA,10,C1003,10     -{BUTTON FLAG Set: Joy 0 Button 10}-
5=UA,10,C1004,10     -{BUTTON FLAG Clear: Joy 0 Button 10}-
6=PA,9,C1003,9     -{BUTTON FLAG Set: Joy 0 Button 9}-
7=UA,9,C1004,9     -{BUTTON FLAG Clear: Joy 0 Button 9}-
8=PA,8,C1003,8     -{BUTTON FLAG Set: Joy 0 Button 8}-
9=UA,8,C1004,8     -{BUTTON FLAG Clear: Joy 0 Button 8}-
10=CP(F+A,9)A,1,C66507,101 ;//OpenPanel101-DBG     -{PANEL_ID_OPEN}-
11=CP(F+A,9)A,1,C66507,1064 ;//OpenPanel1064-Norden     -{PANEL_ID_OPEN}-
12=CP(F+A,10)A,1,C66508,101 ;//ClosePanel101-DBG     -{PANEL_ID_CLOSE}-
13=CP(F+A,10)A,1,C66508,1064 ;//ClosePanel1064-Norden     -{PANEL_ID_CLOSE}-
14=PA,21,CL12:R,0     -{Lua B17_Eng1_restart}-
15=PA,22,CL13:R,0     -{Lua B17_Eng2_restart}-
16=PC,6,CL14:R,0     -{Lua B17_Eng3_restart}-
17=PC,7,CL15:R,0     -{Lua B17_Eng4_restart}-

[LuaFiles]
1=Lua KillAll
2=A2AB17_MixAdj
3=A2AB17_Mixture
4=A2AB17_Turbo
5=B-17_Heater
6=B17_Mechanic
7=Calc_Track
8=ipcReady
9=linda
10=pucker
11=fuelcheckAll
12=B17_Eng1_restart
13=B17_Eng2_restart
14=B17_Eng3_restart
15=B17_Eng4_restart

[Auto.B-17]
1=Lua KillAll
2=Lua B-17_Heater
3=Lua B-17_Windows_both
4=Lua Calc_Track
5=Lua A2AB17_Turbo
6=Lua A2AB17_Mixture
7=Lua A2AB17_MixAdj
8=linda
9=Lua fuelcheckAll
10=Lua B17_Eng1_restart
11=Lua B17_Eng2_restart
12=Lua B17_Eng3_restart
13=Lua B17_Eng4_restart

I've no idea why it runs in LINDA but not FSUIPC.

Edited by Masterius
added additional information

Share this post


Link to post
Share on other sites
59 minutes ago, Masterius said:

I've no idea why it runs in LINDA but not FSUIPC.

Nor have I - assignments look good. Try activating logging for Buttons & Switched and Lua plugins to see if that tells you anything. You can post your log file here. Try without LINDA running as well to see if that's interfering.

Share this post


Link to post
Share on other sites

I've found the issue, but no idea how to fix it. I get this error when trying to run it:

[E] *** LUA Error: ...am\steamapps\common\FSX\Modules\B17_Eng1_restart.lua:61: attempt to call global 'DspShow' (a nil value)

It runs fine in LINDA, but I suspect that's because it's run within the larger file lib-user.lua

function B17_Eng1_restart ()
    ipc.writeLvar("L:Feather1Switch", 0)
    DspShow("Fthr", "1 off")
    ipc.sleep(500)
ipc.clearbitsUB("2434", 1)
ipc.sleep(2000)
ipc.writeLvar("L:FuelValvesSafe",1)
ipc.sleep(750)
ipc.writeLvar("L:Eng1FuelCutOffSwitch",1)
ipc.sleep(1500)
ipc.writeLvar("L:FuelValvesSafe",0)
ipc.sleep(750)
ipc.writeLvar ("L:MixtureLock",0)
ipc.sleep(1500)
ipc.writeLvar("L:MixtureRatioLever1Position", 2)
ipc.sleep(1500)
ipc.setbitsUB("3125", 1)
DspShow("Pump", "1on")
ipc.sleep(1500)
ipc.writeLvar ("L:MixtureLock",1)
ipc.writeSB("0892", 3)
ipc.sleep(750)
restartIfNeeded1 ()
ipc.sleep(30000)
ipc.writeLvar ("AutoCoPilotCowl", 1)
end


function restartIfNeeded1 ()
n = ipc.readLvar("Eng1_RPM")
if n<=250 then
B17_InertStart_show1 ()
else
end
end

function B17_InertStart_show1 ()
ipc.writeLvar("L:Starter12Start", 0)
Inert = round(ipc.readLvar("L:StarterInertiaSoundVolume")/2.5)
    if _MCP1 () then
    DspShow("Inrt", Inert .."%")
    elseif _MCP2 () then
    DspMed1("InrtStrt")
    DspMed2(" " .. Inert .."%")
    end
B17_Engine1_Mesh ()
end

function B17_EngineMesh_stop ()
    ipc.writeLvar("L:Starter12Mesh", 1)
    ipc.writeLvar("L:Starter34Mesh", 1)
    DspMed1("")
    DspShow("stop", "")
    end


function B17_Engine1_Mesh ()
ipc.sleep(12000)
ipc.writeLvar("L:Starter12Mesh", 0)
end
DspShow("Mesh", " " .. 1 .. " ")

Share this post


Link to post
Share on other sites
48 minutes ago, Masterius said:

I've found the issue, but no idea how to fix it. I get this error when trying to run it:

[E] *** LUA Error: ...am\steamapps\common\FSX\Modules\B17_Eng1_restart.lua:61: attempt to call global 'DspShow' (a nil value)

It runs fine in LINDA, but I suspect that's because it's run within the larger file lib-user.lua

Your Lua script calls a function called "DspShow" here:

function B17_Eng1_restart ()
    ipc.writeLvar("L:Feather1Switch", 0)
    DspShow("Fthr", "1 off")

So, where is that function defined? It appears to be missing in your script, which is why you get a compilation error!

Pete

 

Share this post


Link to post
Share on other sites

As Pete says, your lua script is using a LINDA lua library function that isn't present when you run your script outside of the LINDA environment.
To use this outside of LINDA, you would need to include that script, and all its dependencies.

Share this post


Link to post
Share on other sites
On 10/10/2020 at 12:16 PM, Pete Dowson said:

So, where is that function defined? It appears to be missing in your script, which is why you get a compilation error!

 

On 10/10/2020 at 12:50 PM, John Dowson said:

As Pete says, your lua script is using a LINDA lua library function that isn't present when you run your script outside of the LINDA environment.
To use this outside of LINDA, you would need to include that script, and all its dependencies.

OK, I'm admitting I've no idea what I'm doing. I've torn apart every .lua existing in the various folders, and after having done so I've no idea how DspShow is defined. I've specifically looked for "Fthr" to see where and how that is defined, and simply can't find it. I'm at a loss here. 

I've also read all the support manuals and instructions and have exhausted Google, and again come up short with an explanation for DspShow.  Care to take pity on an ignoramous?

Share this post


Link to post
Share on other sites
4 hours ago, Masterius said:

I've torn apart every .lua existing in the various folders, and after having done so I've no idea how DspShow is defined. I've specifically looked for "Fthr" to see where and how that is defined, and simply can't find it. I'm at a loss here. 

Well, I don't know either. If you didn't invent those names yourself, where did you find them and what do you think they do? If you identified where you got this stuff from them then maybe you'll find more information about them and how to use them in the same place?

Pete

 

Share this post


Link to post
Share on other sites
13 hours ago, Masterius said:

I've specifically looked for "Fthr" to see where and how that is defined, and simply can't find it. I'm at a loss here. 

But "Fthr" is just a parameter value to a function, so I'm not surprised that you didn't find that. You should certainly be able to find the definition of the DspShow function somewhere. 
But even if you find that, there are other problems, e.g. functions _MCP1() and _MCP2() aren't defined, nor DspMed1 or DspMed2.
This script is obviously meant to run in the LINDA environment.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • 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.