Jump to content
The simFlight Network Forums
johnk515

Problem with on\off button with QW 787 fsuipc 5 and p3d 4.5

Recommended Posts

I'm using a simple LUA file to switch the capt baroset STD select.  The button is a stay constant on button.  It comes on, but when I push the button again it doesn't change the select button on the panel.  Then when I push again it changes. I have to push the button 2x to get the panel to go on then off, then 2x to go back on.  I have other aircraft that I use constant on/off switches/buttons that it works. 

 

STD Select.lua

Share this post


Link to post
Share on other sites

Many of the newer designers are using "sense" variables. Meaning that they sense the user did something. 
In background coding somewhere, that "sense" var triggers other code to do something.  It then resets itself to zero once done. Acting somewhat like a "toggle" rather than a "set".
This seems to be the case in the 787.

From the simbuilders kit.pdf -
Capt Baroset STD Select (STD Only for CAPT) | 6 | QW_MCP_L_BRST_STD_Button | 1=Pressed

Using a parameter of 1 for both on & off should get it working correctly with your code. The problem is that your constant button may (and probably will) get out of synch with the 787 panel. Using a momentary push button would alleviate that. 

Roman

 

Share this post


Link to post
Share on other sites

That's probably right.  PMDG lets you sync the the STD button.  Plus they have all their events as control codes which makes it easier for me.  And I can live with just clicking on the button.  2 of my biggest problems is the autobrake and the tcas button.  I've been trying to set up the 2 so I can use my T1, T2 for rotating the know for the tcas, and my T3, T4 rocker switches for the autobrake.  These are on my Saitek X52 stick.  Most of my other planes that use the tcas and autobrake have keyboard commands that you can make keyboard letters then assign them to switches with fsuipc.  But making a Lua file to make them move right and left is a little bad on the brain.  I've looked at all kinds of lua stuff, but it gets confusing. 

Share this post


Link to post
Share on other sites

Yes, but it does the same thing.  I can live without that.  I'm just trying to find away to use the buttons on my stick to turn the autobrake and tcas knob.  PMDG has them in their key commands.  

Share this post


Link to post
Share on other sites

If there are key commands, you can assign buttons directly to those. However, reading your earlier post it seems that this works for other aircraft for you, but not the PMDG ones, no?

You could also try mouse macros.  You will probably need to play around with the mouse control codes - I have had success for left/right knob turns with the mouse-wheel up/down codes, but you will need to try them.  I don't have any PMDG aircraft, sorry.

Share this post


Link to post
Share on other sites

Oh, the PMDG I have no problems.  I have all the control codes for the 737, 777, 747.  Those were the easies to setup.  My problem is making a LUA file I.E. auto_brake_switch with a value/range of -1-6, and assigning one of my switches to inc and the other switch do dec.  This is for the QW 787 in P3P v4.5

Share this post


Link to post
Share on other sites
12 hours ago, johnk515 said:

Those were the easies to setup.  My problem is making a LUA file I.E. auto_brake_switch with a value/range of -1-6, and assigning one of my switches to inc and the other switch do dec.

Isn't that just a matter of keeping a copy of the last value sent, and incrementing or decrementing that before sending the result -- with checks on the limts of -1 and +6 of course.

If you explain just what it is you need to know I'm sure we can help.

Pete

 

Share this post


Link to post
Share on other sites

Here's what I came up with for the TCAS and autobrake in 1 lua file.

---------------------------------------------
--Parameters by Number
---------------------------------------------
--1    Turn TCAS Clockwise one position
--2    Turn TCAS Counter Clockwise one position
--3    Turn Autobrake clockwise one position
--4    Turn Autobrake Counter Clockwise one postion

---------------------------------------------
----Variables
---------------------------------------------
"L:QW_AFT_Transponder_Knob"

"L:auto_brake_switch"

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

--Inc TCAS
if ipcPARAM == 1 then

n = ipc.readLvar("L:QW_AFT_Transponder_Knob")
    n = n + 1
    If n > 4
    end

    else
ipc.writeLvar(L:QW_AFT_Transponder_Knob", n)

    end
end

--Dec TCAS
if ipcPARAM == 2 then

n = ipc.readLvar("L:QW_AFT_Transponder_Knob"}
    n = n - 1
    if n < 0
    end

    else
ipc.writeLvar("L:QW_AFT_Transponder_Knob" n)

    end
end

--Inc Autobrakes
if ipcPARAM == 3 then

n = ipc.readLvar("L:auto_brake_switch")
    n = n + 1
    if n > 6
    end
    
    else
ipc.writeLvar("L:auto_brake_switch", n)
    
    end
end

--Dec Autobrakes
if ipcPARAM == 4 then

n = ipc.readLvar("L:auto_brake_switch")
    n = n - 1
    if n < -1
    end
    
    else
ipc.writeLvar("L:auto_brake_switch", n)
    
    end
end
 

I had it read the value of the switch, then add 1 or subtract 1.  And check to see if n was more than 4 or less than 0 for the tcas, and more than 6 or less than -1 for the autobrake.

Share this post


Link to post
Share on other sites

Just a quick look, and some notes for you for the future, hope it helps.
Logging with FSUIPC can help you find any errors keeping the lua from running. 
I use the Logging Tab | "Debug/Trace Lua plugins" and "Send to console window". Very convenient, specially if you have multiple monitors.
Here is what i have found :

  1.  missing comment symbols in your notes at the top, specifically the variables section 
  2.  missing beginning quote in the first ipc.writeLvar attribute
  3.  missing comma separating the attributes on the second ipc.writeLvar
  4.  multiple missing "then"s after previous "if"s
  5.  on the second ipc.readLvar the attribute was surrounded by ( attribute } rather than ( attribute )

Any of the above will cause the lua to fail.

Below is an untested version written slightly different. Instead of using "if"s the lua math library was used to limit the values.
If you plan on adding any more commands to this lua a re-write should be done using the FSUIPC/Lua Event library.
Hope it works for you.

Roman

--[[
Parameters by Number :
1    Turn TCAS Clockwise one position
2    Turn TCAS Counter Clockwise one position
3    Turn Autobrake clockwise one position
4    Turn Autobrake Counter Clockwise one postion

Variables :
"L:QW_AFT_Transponder_Knob" 
"L:auto_brake_switch"
]] 

-- Declare variable
n = 0

-- Inc TCAS
if ipcPARAM == 1 then
	n = ipc.readLvar("L:QW_AFT_Transponder_Knob")
	n = n + 1
	n = math.min(n, 4)
	ipc.writeLvar("L:QW_AFT_Transponder_Knob", n)
end

-- Dec TCAS
if ipcPARAM == 2 then
	n = ipc.readLvar("L:QW_AFT_Transponder_Knob")
	n = n - 1
	n = math.max(n, 0)
	ipc.writeLvar("L:QW_AFT_Transponder_Knob", n)
end

-- Inc Autobrakes
if ipcPARAM == 3 then
	n = ipc.readLvar("L:auto_brake_switch")
	n = n + 1
	n = math.min(n, 6)
	ipc.writeLvar("L:auto_brake_switch", n)
end

-- Dec Autobrakes
if ipcPARAM == 4 then
	n = ipc.readLvar("L:auto_brake_switch")
	n = n - 1
	n = math.max(n, -1)
	ipc.writeLvar("L:auto_brake_switch", n)
end

 

Share this post


Link to post
Share on other sites

I logged the test and here's what I got.

706062 -------------------------------------------------------------------
   798890 D:\Lockheed Martin\Prepar3D v4\SimObjects\Airplanes\QualityWings 787-9\Boeing 787-9 RR.air
   803078 Aircraft="QualityWings 787-9 Virgin Atlantic Airways -SATCOM"
   890219 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   891156 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   891750 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   892172 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   900859 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   901375 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   901781 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   902094 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   906422 Sim stopped: average frame rate for last 97 secs = 27.9 fps
   906422    Max AI traffic was 15 aircraft (Deleted 0)
   906422 -------------------------------------------------------------------
   961156 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   962703 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   963656 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   964469 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   964922 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   965312 *** LUA Error: D:\Lockheed Martin\Prepar3D v4\Modules\QWTcasAutobrake.lua:25: ')' expected near '}'
   972625 Sim stopped: average frame rate for last 29 secs = 29.4 fps
   972625    Max AI traffic was 15 aircraft (Deleted 0)
   972625 -------------------------------------------------------------------
[Log closed by user request, and continued in new file]
 

Roman, I changed the Max and Min around since like the tcas inc the max was 4.  tcas was 0-4 and I didn't want it to go higher.  I don't know what the error means ')' expected near ')' or what needs to change.

Share this post


Link to post
Share on other sites

The original above was fixed..
The log gives the line number where the error occurred --> QWTcasAutobrake.lua:25')' expected near '}'
How in the world did I miss the } where a ) should have been? Time to see the eye doctor I reckon.. 😉 
math.max(val1, val2) &  math.min(val1, val2) are comparators.
They compare the 2 values and give either the lesser (min, a maximum limit) or the greater (max, a minimum limit)  ex.

n = 5
n = n + 1  -- n now equals 6
n = math.min(n, 5) -- n now equals 5 because 5 is the smaller (the minimum) of the 2 comparing numbers --> 5 and 6. 5 is the highest it will go acting as an upper limit.

It is correct as is, even in XML gauge scripting the min / max throws people a curve.

Roman

Share this post


Link to post
Share on other sites
11 hours ago, johnk515 said:

Where should the } be. I'm still getting that error.

Roman already corrected this for you in the above post - it was this line:

ipc.readLvar("L:QW_AFT_Transponder_Knob"}

and the log gives the line number where the error occurs, as Roman said:

12 hours ago, spokes2112 said:

The log gives the line number where the error occurred --> QWTcasAutobrake.lua:25')' expected near '}'

 

John

 

Share this post


Link to post
Share on other sites

I guess I need my eyes check also.  I had looked all over the file and couldn't see anything wrong until now.  Well both the tcas and the autobrake works now.  Thanks for all the help.

 

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.