In the meantime you can use this code.
1-The "Switch Type" is now a user property (1 to 8).
2- A legend can be added to the switch as a user property (leave the field empty if no legend)
(Create a clone of the instrument, then copy/Paste (completely replace the existing code) by this one
Code: Select all
------------------------------------------------------------
-- VERTICAL GENERIC SWITCH Type 1 --
-- J. Zahar v5.0 May 2023 --
-------------------------------------------------------------------
----------------- FUNCTION DEFINITION ----------------------
-- MODIFY the variables values to get the desired function --
-------------------------------------------------------------------
-- Switch legend, leave the field empty if no Legend
switch_name_prop = user_prop_add_string("Switch Legend", "", "Switch Legend, leave empty if no legend")
switch_name=user_prop_get(switch_name_prop)
switch_name=string.sub(switch_name, 1,12 )
switch_color="white" --The color, can be color string like "red", "blue", "cyan", etc. etc. Can also be a hex value, "#FFFFFF"
-- Xplane Function operated by the switch when ON --
-- modify the variable according to taste --
xpl_switch_function="sim/operation/pause_toggle" -- Xplane function/variable to perform
xpl_switch_type="INT" -- Xplane function variable type returned
-- Fsx/MSFS Function operated by the switch
-- modify the Simvariable according to taste --
fsx_switch_var="" -- FSX/MSFS SimVar !!!! ONLY BOOLEAN TYPE ARE SUPPORTED
fsx_switch_type="Bool" -- FSX function variable type returned
---- OR ---
-- modify the Event according to taste --
fsx_switch_event_ON="PAUSE_ON" -- FSX/MSFS Event to perform
fsx_switch_event_OFF="PAUSE_OFF" -- FSX/MSFS Event to perform
------------------------------------------------------------
-- END OF FUNCTION DEFINITION --
-- Do not modify the code beyond this point --
------------------------------------------------------------
-- Type of switch to display :
-- 1: Vertical Rocker switch (color RED) with complete black bezel (standalone switch)
-- 2: Vertical Rocker switch (color RED) with left bezel only (to be assembled with another center or right switch)
-- 3: Vertical Rocker switch (color RED) with right bezel only (to be assembled with another center or left switch)
-- 4: vertical Rocker switch (color RED) without left/right bezel (to be assembled in between another left or right switch)
-- 5: Vertical Rocker switch (color WHITE) with complete black bezel (standalone switch)
-- 6: Vertical Rocker switch (color WHITE) with left bezel only (to be assembled with another center or right switch)
-- 7: Vertical Rocker switch (color WHITE) with right bezel only (to be assembled with another center or right switch)
-- 8: vertical Rocker switch (color WHITE) without left/right bezel (to be assembled in between another left or right switch)
switch_type = user_prop_add_integer("Switch Type",1, 8, 1, "Type of switch (1-8)")
switch_display_type= user_prop_get(switch_type)
-- SWITCH
function switch_click_callback(position)
if position == 0 then
switch_set_position(switch_id, 1)
xpl_dataref_write(xpl_switch_function,xpl_switch_type, 1)
fsx_event(fsx_switch_event_ON)
fs2020_event(fsx_switch_event_ON)
fsx_variable_write(fsx_switch_var,fsx_switch_type,true)
fs2020_variable_write(fsx_switch_var,fsx_switch_type,true)
elseif position == 1 then
switch_set_position(switch_id, 0)
xpl_dataref_write(xpl_switch_function,xpl_switch_type, 0)
fsx_event(fsx_switch_event_OFF)
fs2020_event(fsx_switch_event_OFF)
fsx_variable_write(fsx_switch_var,fsx_switch_type,false)
fs2020_variable_write(fsx_switch_var,fsx_switch_type,false)
end
end
if switch_display_type==1 then
switch_id = switch_add("red_ver_complete_off.png", "red_ver_complete_on.png", 0,0,70,130,switch_click_callback)
end
if switch_display_type==2 then
switch_id = switch_add("red_ver_left_off.png", "red_ver_left_on.png", 0,0,70,130,switch_click_callback)
end
if switch_display_type==3 then
switch_id = switch_add("red_ver_right_off.png", "red_ver_right_on.png", 0,0,70,130,switch_click_callback)
end
if switch_display_type==4 then
switch_id = switch_add("red_ver_center_off.png", "red_ver_center_on.png", 0,0,70,130,switch_click_callback)
end
if switch_display_type==5 then
switch_id = switch_add("white_ver_complete_off.png", "white_ver_complete_on.png", 0,0,70,130,switch_click_callback)
end
if switch_display_type==6 then
switch_id = switch_add("white_ver_left_off.png", "white_ver_left_on.png", 0,0,70,130,switch_click_callback)
end
if switch_display_type==7 then
switch_id = switch_add("white_ver_right_off.png", "white_ver_right_on.png", 0,0,70,130,switch_click_callback)
end
if switch_display_type==8 then
switch_id = switch_add("white_ver_center_off.png", "white_ver_center_on.png", 0,0,70,130,switch_click_callback)
end
legend = txt_add(switch_name, "roboto_regular.ttf; size:11; color:"..switch_color.."; halign:center;",0, 5, 70, 20)
function new_switch_pos(sw_on)
if sw_on == 0 then
switch_set_position(switch_id, 0)
elseif sw_on == 1 then
switch_set_position(switch_id, 1)
end
end
function new_switch_pos_fsx(sw_on)
sw_on = fif(sw_on, 1, 0)
new_switch_pos(sw_on)
end
xpl_dataref_subscribe(xpl_switch_function,xpl_switch_type,new_switch_pos)
fsx_variable_subscribe(fsx_switch_var, fsx_switch_type, new_switch_pos_fsx)
fs2020_variable_subscribe(fsx_switch_var, fsx_switch_type, new_switch_pos_fsx)