Using Lua Script to Control Landing Lights
-
- Posts: 12
- Joined: Sun Jun 24, 2018 11:23 am
- Location: Texas
Using Lua Script to Control Landing Lights
Hello All:
I thought I'd share a simple script I wrote that can be used to toggle the C310's landing lights using a hardware switch.
I have been wanting to utilize my CH Products Throttle Quadrant to control several systems on the C310 Redux.
After having recent success using FSUIPC and Lua script to get the 310 props to go into feather range using the quadrant prop axis, I set out to use my new found scripting knowledge to toggle the 310's landing light switch and light extend / retract animation using a switch on my CH Throttle quadrant.
Note: The 310 prop feather script can be found in the 310 Support Forum.
If you want to assign the 310's landing lights to a hardware button:
The end result behavior is this:
In the the virtual cockpit-
--Set C310 Landing Light Switch State
--Control Codes
--66059 LANDING_LIGHTS_ON
--66060 LANDING_LIGHTS_OFF
--ipcPARAM = 0 is moving to OFF
--ipcPARAM = 1 is moving to ON
--Switch States
--0 = Off
--1 = Extended
--2 = On
ipc.log("ipcPARAM: "..ipcPARAM)
SwitchState = ipc.readLvar("L:SwitchLL")
if ipcPARAM == 0 then
ipc.log("Moving to OFF")
if SwitchState == 2 then
ipc.log("Switch state is 2, so move to 1 'extended' and turn off light")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)
--Turn the lights off
ipc.control(66060)
end
if SwitchState == 1 then
ipc.log("Switch state is 1, so move to 0 'retracted'")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 0)
end
end
if ipcPARAM == 1 then
ipc.log("Moving to ON")
if SwitchState == 1 then
ipc.log("Switch state is 1, so move to 2 and turn on light")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 2)
--Turn the light on
ipc.control(66059)
end
if SwitchState == 0 then
ipc.log("Switch state is 0, so move to 1 'extended'")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)
end
end
ipc.log("Toggle Landing Light Switch Done")
I thought I'd share a simple script I wrote that can be used to toggle the C310's landing lights using a hardware switch.
I have been wanting to utilize my CH Products Throttle Quadrant to control several systems on the C310 Redux.
After having recent success using FSUIPC and Lua script to get the 310 props to go into feather range using the quadrant prop axis, I set out to use my new found scripting knowledge to toggle the 310's landing light switch and light extend / retract animation using a switch on my CH Throttle quadrant.
Note: The 310 prop feather script can be found in the 310 Support Forum.
If you want to assign the 310's landing lights to a hardware button:
- Create a Lua Script file and place it in the Modules folder
- Use FSUIPC to run the Lua script when your button hardware is pressed
- When programming the button use a parameter of "0" for OFF, and a parameter of "1" for ON
The end result behavior is this:
In the the virtual cockpit-
- If Landing Light Switch is in the OFF POSITION, pressing your hardware ON button EXTENDS the lights and moves the virtual switch to the CENTER POSITION
- If Landing Light Switch is in the CENTER POSITION, pressing your hardware ON button turns the lights ON and moves the virtual switch to the ON POSITION
- If Landing Light Switch is in the ON POSITION, pressing your hardware OFF button turns the lights OFF and moves the virtual switch to the CENTER POSITION
- If Landing Light Switch is in the CENTER POSITION, pressing your hardware OFF button RETRACTS the lights and moves the virtual switch to the OFF POSITION
--Set C310 Landing Light Switch State
--Control Codes
--66059 LANDING_LIGHTS_ON
--66060 LANDING_LIGHTS_OFF
--ipcPARAM = 0 is moving to OFF
--ipcPARAM = 1 is moving to ON
--Switch States
--0 = Off
--1 = Extended
--2 = On
ipc.log("ipcPARAM: "..ipcPARAM)
SwitchState = ipc.readLvar("L:SwitchLL")
if ipcPARAM == 0 then
ipc.log("Moving to OFF")
if SwitchState == 2 then
ipc.log("Switch state is 2, so move to 1 'extended' and turn off light")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)
--Turn the lights off
ipc.control(66060)
end
if SwitchState == 1 then
ipc.log("Switch state is 1, so move to 0 'retracted'")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 0)
end
end
if ipcPARAM == 1 then
ipc.log("Moving to ON")
if SwitchState == 1 then
ipc.log("Switch state is 1, so move to 2 and turn on light")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 2)
--Turn the light on
ipc.control(66059)
end
if SwitchState == 0 then
ipc.log("Switch state is 0, so move to 1 'extended'")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)
end
end
ipc.log("Toggle Landing Light Switch Done")
- ThomasAH
- Posts: 90
- Joined: Wed Dec 20, 2017 4:45 pm
Re: Using Lua Script to Control Landing Lights
Thank you!
Here is your (unchanged) code marked with [code]...[/code] to keep indentation and such.
Here is your (unchanged) code marked with [code]...[/code] to keep indentation and such.
Code: Select all
--Set C310 Landing Light Switch State
--Control Codes
--66059 LANDING_LIGHTS_ON
--66060 LANDING_LIGHTS_OFF
--ipcPARAM = 0 is moving to OFF
--ipcPARAM = 1 is moving to ON
--Switch States
--0 = Off
--1 = Extended
--2 = On
ipc.log("ipcPARAM: "..ipcPARAM)
SwitchState = ipc.readLvar("L:SwitchLL")
if ipcPARAM == 0 then
ipc.log("Moving to OFF")
if SwitchState == 2 then
ipc.log("Switch state is 2, so move to 1 'extended' and turn off light")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)
--Turn the lights off
ipc.control(66060)
end
if SwitchState == 1 then
ipc.log("Switch state is 1, so move to 0 'retracted'")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 0)
end
end
if ipcPARAM == 1 then
ipc.log("Moving to ON")
if SwitchState == 1 then
ipc.log("Switch state is 1, so move to 2 and turn on light")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 2)
--Turn the light on
ipc.control(66059)
end
if SwitchState == 0 then
ipc.log("Switch state is 0, so move to 1 'extended'")
--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)
end
end
ipc.log("Toggle Landing Light Switch Done")
-
- Posts: 12
- Joined: Sun Jun 24, 2018 11:23 am
- Location: Texas
Re: Using Lua Script to Control Landing Lights
Thank you Thomas, I was not aware of the tag.
Good stuff!
--Chris
Good stuff!
--Chris
-
- Posts: 1023
- Joined: Mon Sep 06, 2010 3:47 pm
Re: Using Lua Script to Control Landing Lights
You select the indicated icon either before pasting your code/script in between the tags, or you can highlight the code/script and then click the button. Of course you could also just type in the "code box" tags manually:
