Switch Function

Help creating logic scripts for Air Manager Instruments

Moderators: russ, Ralph

Post Reply
Message
Author
TKSim
Posts: 3
Joined: Fri May 12, 2023 3:41 pm

Switch Function

#1 Post by TKSim »

Hello all,

I am building an Air Manager panel for the Challenger 300.

I have struggled to use the switch function. I need a button that can turn the electrical batteries on and off. For some reason the switch function will not change the on / off images on the Air Manager side.

Could someone give me a simple switch script that works? If I can see something that works, it helps me a lot!

Thanks!

P.S. I am using X-Plane 11, MacOS.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Switch Function

#2 Post by Sling »

What’s wrong with the examples on the wiki. They should show you what you need.

steveald
Posts: 10
Joined: Sat Oct 15, 2022 2:21 am

Re: Switch Function

#3 Post by steveald »

Hi TKSim,

--DOME SWITCH

sw_DOME = switch_add("tog_mid.png","tog_down.png", 5,0,70,108,
function()
xpl_command("FJS/Q4XP/Switches/dome")
end)
----------------------------------------------------------------------------------------------------------
xpl_dataref_subscribe("FJS/Q4XP/Manips/TwoSwitch_Ctl", "INT[64]",
function (state)
switch_set_position(sw_DOME, state[21])
end)

The switch on the instrument tells X-Plane to execute a command, which changes a dataref value which is subscribed to which changes the graphics on the instrument via the switch_set_position statement.

It sounds like you are doing the first part, but not the second part.

I'm not sure how to explain it better than that, hope it helps.

Steve

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Switch Function

#4 Post by Ralph »

The first step is to find a command or dataref that lets you set the switch position.

TKSim
Posts: 3
Joined: Fri May 12, 2023 3:41 pm

Re: Switch Function

#5 Post by TKSim »

Good info.

I did try that code. it changes the X-Plane side. But it still does not change AirManager's graphics.

The XPL command that I am using, is not an "on / off" position. it's just a toggle. Whichever position the Sim is at it will do the opposite.

my command is: "cl300/electrical/batt_left" as you can see, I can't turn it on or off. How would I use the switch function with that?


Thanks!

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Switch Function

#6 Post by Ralph »

If you just add xpl_command("cl300/electrical/batt_left") to a script and start the instrument, do you see it toggle in the simulator?

TKSim
Posts: 3
Joined: Fri May 12, 2023 3:41 pm

Re: Switch Function

#7 Post by TKSim »

Yes, it does.

User avatar
Sling
Posts: 5237
Joined: Mon Sep 11, 2017 2:37 pm
Contact:

Re: Switch Function

#8 Post by Sling »

Hi,

If the aircraft dev has done a good job with the aircraft then the status of this battery switch should be stored in either a standard or their own custom dataref. In that case you can have the AM switch in sync with the sim by following the preferred wiki example. If not then follow the alternative wiki example.

Hope that helps.

User avatar
Ralph
Posts: 7878
Joined: Tue Oct 27, 2015 7:02 pm
Location: De Steeg
Contact:

Re: Switch Function

#9 Post by Ralph »

As Sling said, now figure out which dataref changes with the switch and what values it has for each position. It'll most probably be 0 and 1. It can be a pain to find sometimes :)

User avatar
jph
Posts: 2846
Joined: Fri Apr 10, 2020 12:50 pm
Location: Somewhere over the rainbow..

Re: Switch Function

#10 Post by jph »

For some reason the switch function will not change the on / off images on the Air Manager side
seems to be the main issue.................................................................................. ;)
Joe. CISSP, MSc.

Post Reply