FSX Need help dsd_fsx_xml_sound

#1
I know there are lost of dsd_fsx_xml_sound threads, but T couldn't find an answer in any of those. Anyway, I downloaded dsd_fsx_xml_sound so that I could hook some sounds up to panel switches on FSX. After reading the readme 5 times, I felt confident that I could install everything and it would work. I decided to make an electric hydraulic pump switch play a sound when switched on. After much trial and error, I got the sound to play, but as a result destroyed any other functionality the switch had. The switch no longer would move and the sound would come on and stay on no matter how many times I would click the switch. I was told that I could find the best help here on this website. Here is the section of the XML that I attempted to modify (for some reason the script I added isn't there anymore):

<Element id="HYD APU">

</Element>
<FloatPosition>85.000,166.000</FloatPosition>
<Select id="Select">
<Expression id="Expression">
<Minimum>0.000</Minimum>
<Maximum>1.000</Maximum>
<Script>(A:Hydraulic Switch:3, bool)</Script>
</Expression>
<Case id="Case">
<ExpressionResult>0.000</ExpressionResult>
<Image id="Image" Name="popup_overhead_switch_hydraulic_apu_off.bmp">
<Transparent>True</Transparent>
</Image>
</Case>
<Case id="Case">
<ExpressionResult>1.000</ExpressionResult>
<Image id="Image" Name="popup_overhead_switch_hydraulic_apu_on.bmp">
<Transparent>True</Transparent>
</Image>
</Case>
</Select>
</Element>

I believe that I was using ContolVar 2. If someone can tell me how to script this so that the switch has its regular functionality and plays the file when the switch is on. I was also wondering if there is any way that I can make the switch play different sound files for turning the pump on and off.
 
#3
So then I would want to add it to this script:

<MouseArea id="HYD APU">
<FloatPosition>113.000,169.000</FloatPosition>
<Size>40,41</Size>
<CursorType>Hand</CursorType>
<MouseClick id="MouseClick">
<Script>3 (&gt;K:HYDRAULIC_SWITCH_TOGGLE)</Script>
<ClickType>LeftSingle</ClickType>
</MouseClick>
<Tooltip id="Tooltip">
<DefaultId>TOOLTIPTEXT_B737_HYD_ELEC_SWITCH</DefaultId>
</Tooltip>
</MouseArea>

I did try it here too but had no luck.
 

Heretic

Resource contributor
#4
I'm not in the mood for lengthy explanations, but these are the basics to make a panel switch play a sound once:

Code:
<MouseClick id="MouseClick">
<Script>3 (&gt;K:HYDRAULIC_SWITCH_TOGGLE) 1 (&gt;L:Hydraulic Switch Sound, number)</Script>
<ClickType>LeftSingle</ClickType>
</MouseClick>
For a loop, you need a gauge like:
Code:
<?xml version="1.0" encoding="UTF-8"?>

<SimBase.Document Type="AceXML" version="1,0">
  <Descr>AceXML Document</Descr>
  <Filename>XML_Sound_Control.xml</Filename>
  <SimGauge.Gauge id="Gauge" ArtDirectory=".">
  <FloatPosition>0.000,0.000</FloatPosition>
  <Size>1,1</Size>
  <Update_When_Hidden>True</Update_When_Hidden>  
  <Update id="Interactions">
  <Script>
  (A:HYDRAULIC SWITCH,bool) 1 == (L:Hyd_Pump_Sound,number) 0 == and
  if{ 2 (&gt;L:hydraulic pump sound,number) }
  (A:HYDRAULIC SWITCH,bool) 0 == (L:Hyd_Pump_Sound,number) 0 != and
  if{ 0 (&gt;L:hydraulic pump sound,number) }
  </Script>
  </Update>
  </SimGauge.Gauge>
</SimBase.Document>
Point the XML_sound.ini to the "(L:hydraulic pump sound,number)" variable, make sure the corresponding sound entry points to a valid .wav file and you should be good to go.



Download any of Daniel Gauthier's Cockpit Sound mods from Avsim to get pointers on how to successfully set up switch sounds for FSX cockpits.
 
#5
Ok so both scritps work. The loop script however has made it so that the switch no longer moves. Otherwise it functions as normal and does trigger the hydraulic system. The switch click sound works but I'm wondering if there is any way possible that I could make the switch shutting off play a different file than switching on. Also is there a way to make the sound not play outside?
 

Heretic

Resource contributor
#6
Code:
A:Hydraulic_Variable 1 == L:Hydraulic_Check_Variable 0 == and
if{  1 >L:Hydraulic_Check_Variable 1 >L:Hydraulic_Pump_Start_Sound 0 >L:Hydraulic_Pump_Loop_Sound }

A:Hydraulic_Variable 1 == L:Hydraulic_Check_Variable 1 == and
if{  2 >L:Hydraulic_Pump_Loop_Sound }

A:Hydraulic_Variable 0 == L:Hydraulic_Check_Variable 1 == and
if{  0 >L:Hydraulic_Check_Variable 1 >L:Hydraulic_Pump_Stop_Sound 0 >L:Hydraulic_Pump_Loop_Sound }
(Requires more formatting to work.)

I think the view-dependant stuff is possible with some extra code and the "DSD View Status" gauge.
 
#8
Thanks so much for the help for the help. Sorry to bother you guys more, but what extra formatting does that new script require to work? Also, is there any possible way to have the switch make one sound when getting switched on and a different one when getting switched off? That would be the last piece of
 
#9
Code:
A:Hydraulic_Variable 1 == L:Hydraulic_Check_Variable 0 == and
if{  1 >L:Hydraulic_Check_Variable 1 >L:Hydraulic_Pump_Start_Sound 0 >L:Hydraulic_Pump_Loop_Sound }

A:Hydraulic_Variable 1 == L:Hydraulic_Check_Variable 1 == and
if{  2 >L:Hydraulic_Pump_Loop_Sound }

A:Hydraulic_Variable 0 == L:Hydraulic_Check_Variable 1 == and
if{  0 >L:Hydraulic_Check_Variable 1 >L:Hydraulic_Pump_Stop_Sound 0 >L:Hydraulic_Pump_Loop_Sound }
(Requires more formatting to work.)
Cool pseudo code, but as you say some formatting may be required?

To begin with, don't know what A:Hydraulic_Variable stands for but supposing both it and L:Hydraulic_Check_Variable are bool then you can cut a bit of dead wood by pseudo-coding line 1 as:

A:Hydraulic_Variable L:Hydraulic_Check_Variable ! and

(ditto for the other boolean conditions in lines 3 and 5)

More problematic is the fact that if this first condition is true then the second one (line 3) becomes also true. Can't be what's intended, or else there must be a better way of putting it.

Next if you consider all three boolean conditions then it seems you are missing the scenario where A:Hydraulic_Variable and L:Hydraulic_Check_Variable are both false (0). So nothing happens then?

To sum up, rather than use three complex boolean conditions the good old if - then - else construct, although more difficult to read, would be more efficient and less error prone. I would write it down, too, but not knowing what the variable units are that's pretty pointless.

Er, gotta say xml coding isn't my forte, so take the above with a pinch of salt, or shall we say pinch pinch pinch and and ... the resident gurus in the field here will correct me no doubt.
 
Last edited:

Heretic

Resource contributor
#10
I was as hungover as half a pig in the butcher's freezer when writing the code and clearly labeled it "pseudo".
But as you seem to be as sober as an imam before the morning prayer, why don'tcha just help out with some real code here instead of being all like "won't work...doesn't work, yadda, yadda"?

And by the way: I've found "if{...} else{...}" too impractical for this kind of scenario.
 

Heretic

Resource contributor
#11
Code:
<?xml version="1.0" encoding="UTF-8"?>

<SimBase.Document Type="AceXML" version="1,0">
<Descr>AceXML Document</Descr>
<Filename>XML_Sound_Control.xml</Filename>
<SimGauge.Gauge id="Gauge" ArtDirectory=".">
<FloatPosition>0.000,0.000</FloatPosition>
<Size>1,1</Size>
<Update_When_Hidden>True</Update_When_Hidden>
<Update id="Interactions">
<Script>
<!-- Hydraulic pump start sound -->
(A:HYDRAULIC SWITCH,bool) 1 == (L:Hyd_Pump_State,number) 0 == and
if{ 1 (&gt;L:hydraulic pump start sound,number) 1 (>L:Hyd_Pump_State,number) }

<!-- Check if start sound has been played, then switch sound control state -->
(A:HYDRAULIC SWITCH,bool) 1 == (L:Hyd_Pump_State,number) 1 == and (L:hydraulic pump start sound,number) 0 == and
if{ 2 (>L:Hyd_Pump_State,number) }

<!-- When state is "2" and sim is not paused and view is inside, play the loop sound -->
(L:ViewSystemStatus, number) 1 ==  (L:ViewSystemStatus, number) 2 == or (L:FSSimIsPaused, number) 0 == or
(A:HYDRAULIC SWITCH,bool) 1 == and  (L:Hyd_Pump_State,number) 2 == and  (L:hydraulic pump running sound,number) 0 == and
if{ 2 (&gt;L:hydraulic pump running sound,number) }

<!-- Pause Loop Sound if sim is paused or view is not in the cockpit -->
(L:ViewSystemStatus, number) 1 !=  (L:ViewSystemStatus, number) 2 != or (L:FSSimIsPaused, number) 1 == or
(A:HYDRAULIC SWITCH,bool) 1 == and (L:Hyd_Pump_State,number) 2 == and (L:hydraulic pump running sound,number) 2 == and 
if{ 0 (&gt;L:hydraulic pump running sound,number) }

<!-- End Loop and play "off" sound when switch is clicked again, then reset control variable -->
(A:HYDRAULIC SWITCH,bool) 0 == (L:Hyd_Pump_State,number) 2 == and
if{ 1 (&gt;L:hydraulic pump stop sound,number) 0 (&gt;L:hydraulic pump running sound,number) 0 (>L:Hyd_Pump_State,number)  }
</Script>
</Update>
</SimGauge.Gauge>
</SimBase.Document>
Untested and I bet it still could be done more effectively, but it's better than nothing.
 
#12
I was as hungover as half a pig in the butcher's freezer when writing the code and clearly labeled it "pseudo".... why don'tcha just help out with some real code here instead of being all like "won't work...doesn't work, yadda, yadda"
Begging your pardon, but you did not "clearly label it 'pseudo" -- I did. And it's been some time since somebody told me I was like "yadda yadda". Must have asked for it somehow.
 

Heretic

Resource contributor
#14
Begging your pardon, but you did not "clearly label it 'pseudo" -- I did. And it's been some time since somebody told me I was like "yadda yadda". Must have asked for it somehow.
I'm basically spoon-feeding someone with code here*, so excuse me if I do not appreciate being "talked to from the sidelines" in the process. (I hope "von der Seite angelabert werden" translates that way.)



*No offense, Req757. If you need to do more work with sounds and XML code, try to get some simpler stuff first to get comfortable and then move on to the more complex things like this.



Nah the Tin man is just that way. Nothing personal. You have to have an iron skin to be around him.
I really like Dr. Cox from "Scrubs", if that helps explaining things.
 
#15
So let me then reiterate what I need help with. I need a code that can enable an electric hydraulic switch on a panel play a sound once when the switch is switched on, play a loop when the pump is running (I know how to do this one), and play another sound when the switch shuts off while still allowing the switch to move.The original script for the switch is this: (A:Hydraulic Switch:3, bool). I also may want to apply this to a second hydraulic switch on the panel, but if the code has to conflict with itself then don't bother with that. No offense taken that I'm not experinced with XML, but this is the only thing I will ever use dsd_fsx_xml_sound and xml code for.
 

Heretic

Resource contributor
#16
Did you even look at the code in #11?

You need to change "(A:Hydraulic Switch, bool)" to "(A:Hydraulic Switch:3, bool)" but other than that, it should do.
 
#17
Task
I need a code that can enable an electric hydraulic switch on a panel play a sound once when the switch is switched on, play a loop when the pump is running (I know how to do this one), and play another sound when the switch shuts off while still allowing the switch to move.The original script for the switch is this: (A:Hydraulic Switch:3, bool).

Pseudocode:
if A:hydswitch OFF then { playswitchsoundON; togglepumpON; playloopsound }
els{ playswitchsoundOFF; togglepumpOFF; stoploopsound }

Update: if A:hydswitch ON (pump_running) then { if in spotview then mute loopsound else unmute it }

Full code:
Code:
<Gauge Name="Hydraulics Switch" Version="1.0">
  <Update>
    (A:HYDRAULIC SWITCH:3, bool) if{ (L:ViewSystemStatus, number) 0 == if{ 2 (>L:DSDGlobals, number)  } els{ 3 (>L:DSDGlobals, number) } }
  </Update>
  <Element>
    <Position X="0" Y="0"/>
    <Image Name="Monit_BG.bmp" UseTransparency="Yes" ImageSizes="34,24,34,24"/>
  </Element>
  <Mouse>
    <Area Left="0" Width="34" Top="0" Height="34">
    <Tooltip>Hydraulics Switch</Tooltip>
    <Cursor Type="Hand"/>
    <Click>
      (A:HYDRAULIC SWITCH:3, bool) ! if{ 1 (>L:switchsoundON) 3 (>K:HYDRAULIC_SWITCH_TOGGLE) 2 (>L:pumploopsound) }
      els{ 1 (>L:switchsoundOFF) 3 (>K:HYDRAULIC_SWITCH_TOGGLE) 0 (>L:pumploopsound) }
    </Click>
    </Area>
  </Mouse>
</Gauge>
Tested in FSX SP2.

Statistics: Number of L:variables for control structures: 0; number of boolean conditions: 0; nested curlies: 1.

Notes. (1) <Element> section needs to be adapted to 'animated' graphics. (2) Make sure aircraft.cfg has the proper pumps assigned. (3) Toggle pumps OFF on initialization (ON by default).

Comments?
 
Last edited:
#18
FWIW a refinement. You might want to replace the <Element> section in my previous by the following version which uses your two bmp's.
Code:
  <Element>
    <Position X="0" Y="0"/>
    <Select>
      <Value>(A:HYDRAULIC SWITCH:3, bool)</Value>
      <Case Value="0">
        <Image Name="popup_overhead_switch_hydraulic_apu_off.bmp"/>
      </Case>
      <Case Value="1">
        <Image Name="popup_overhead_switch_hydraulic_apu_on.bmp"/>
      </Case>
    </Select>
  </Element>
Works fine here as a standalone gauge. Try it standalone first to see if it works in your setup, then integrate into the larger gauge that you already have.
 
Top