* NOTE: I updated this post on 1/16/17 to clarify how you find the initial assignments of axes and buttons.
The one lingering barrier to my complete switch to X-Plane was the inability to use both sets of the Basement Sim’s controls. It seems that in X-Plane if roll/pitch/yaw are assigned to more than one controller, only one will work and X-Plane disregards the other. (This is not the case with FSX or P3D, which simply read whichever control provides the most recent or largest input.) Only one set of working controls is a real problem for me, as being able to fly with family, friends, etc. is a big part of what I enjoy about the Basement Sim.
There is an answer, though, and it turns out it is Lua. From the Lua website:
Lua is a powerful and fast programming language that is easy to learn and use and to embed into your application. Lua is designed to be a lightweight embeddable scripting language and is used for all sorts of applications from games to web applications and image processing.
Lots of simmers and cockpit builders use Lua to write little bits of computer code, called “scripts,” that allow them to execute unique commands (like having the buttons they installed in their panel turn on the cabin lights). Lua scripts are like little apps you can run to get things done that the sim software won’t do itself.
X-Plane is very easy to integrate with Lua thanks to the FlyWithLua plugin. I had posted on the X-Plane.org forums that I was hoping the final release version of X-Plane 11 would allow multiple sets of controls, and one of the very helpful folks in that community — Teddii — responded that a Lua script might be the answer. He said I should be able to write a script for one of the buttons on my yoke where if I flip the button to the left the left controls are live, and if I flip it to the right the right controls are live. He even volunteered possible code.
Getting the code to work meant finding out which axis numbers X-Plane was associating with each of the yokes. Fortunately every time you launch X-Plane FlyWithLua puts a little .TXT file called “initial_assignments.txt” in its plugin folder that shows initial joystick and button assignments. To find my axes and button assignment numbers I first went into X-Plane’s joystick configuration screen and assigned the axes of BOTH yokes to pitch and yaw. This gives you a warning that you have dual assignments in X-Plane, but that’s OK. I also assigned the button that I wanted to use to pass control of the airplane to a command I would recognize (in my case, calling ATC). Looking at the initial_assignments.txt file I could see the pitch, roll, and yaw axes for both yokes and the button numbers for the left / right switch on my Yoko yoke (which X-Plane reads as two buttons – one for each position – rather than as one, and I had assigned BOTH to call ATC in the joystick configuration screen). You will see commands like this in the initial_assignments.txt file:
set_axis_assignment( 0, "roll", "normal" ) set_axis_assignment( 1, "pitch", "normal" ) set_axis_assignment( 3, "yaw", "normal" )
… and …
set_button_assignment( (4*40) + 1, "sim/operation/contact_atc" )
You need to do a little math for the button assignment: (4*40)+1, for example, is 161. That’s the button number for the MyAirplaneYourAirplane code. You may also need to guess which set of axis assignments are the left and right controls, but that’s easy to change if you get it wrong.
I added these variables to Teddii’s initial code, put the “My Airplane Your Airplane.txt” script file in the FlyWithLua scripts folder, and gave it a go. Partial success: it worked in swapping to the right controls, but would not swap them back to the left. Looking at the joystick configuration window in X-Plane I could see that I again had conflicting yaw / pitch / roll controls, and deduced that while the swap from left to right worked, the script did not clear the assignments for the left yoke, resulting in the same problem I had started with (dual-assigned controls).
So I just modified the script a little bit, adding lines to assign the axes that I’m switching away from to “none.” SUCCESS! It worked, and now I’m able to easily pass control of the airplane to a passenger by flipping the yoke switch to the right, and take it back by flipping it back to the left.
The final code follows, and you are welcome to use it if you like. Thanks again for Teddii for his help as I would not have been able to do this without his initial and very helpful code. Also, there is a nice primer on getting started with FlyWithLua here.
My Airplane / Your Airplane FlyWithLua Script
-- axis numbers for left yoke
L_axisPitch = 75
L_axisRoll = 76
L_axisPedal = 52
-- axis numbers for right yoke
R_axisPitch = 25
R_axisRoll = 26
R_axisPedal = 2
function yoke_switch()
if button (486) and not last_button(486)
then
-- activate right yoke
set_axis_assignment(R_axisPitch, "pitch", "normal" ) --"normal" or "reverse"
set_axis_assignment(R_axisRoll, "roll", "normal" )
set_axis_assignment(R_axisPedal, "yaw", "normal" )
-- DEactivate left yoke
set_axis_assignment(L_axisPitch, "none", "normal" ) --"normal" or "reverse"
set_axis_assignment(L_axisRoll, "none", "normal" )
set_axis_assignment(L_axisPedal, "none", "normal" )
end
if button (480) and not last_button(480)
then
-- activate left yoke
set_axis_assignment(L_axisPitch, "pitch", "normal" ) --"normal" or "reverse"
set_axis_assignment(L_axisRoll, "roll", "normal" )
set_axis_assignment(L_axisPedal, "yaw", "normal" )
-- DEactivate right yoke
set_axis_assignment(R_axisPitch, "none", "normal" ) --"normal" or "reverse"
set_axis_assignment(R_axisRoll, "none", "normal" )
set_axis_assignment(R_axisPedal, "none", "normal" )
end
end
-- check for the switch button every frame ...
do_every_frame("yoke_switch()")
-- end

Leave a Reply
You must be logged in to post a comment.