• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Custom toggle switch sounds

Messages
465
Country
ca-ontario
I am trying to add click sounds to all the switches and knobs in the VC of my current project using Doug's sound gauge but I'm having problems with getting the sounds working for switches operated by custom L:Vars. I've got the sounds working for any stock functions that use K:Vars.

The problem I have is that I can either get the sound to play once only on the initial operation of the switch or it repeats endlessly whether the switch is clicked or not.

I am using a 2D xml gauge to trigger the sounds with my code in the 'Update' section which is the way I did it on another project and that worked fine for canopy and door sounds but it doesn't appear to be working as well this time.

Here is the code I am trying to use at the moment, this is for one switch that I am using as a test example and once I can get the syntax/operation correct I plan to adapt it to the dozens of other custom switches in the VC.

'L:Boxcar_ht_zone_1_switch' is the Lvar from my modeldef.xml file and the one used on the model part
'L:Boxcar_ht_zone_1_SND' is the Lvar in the 2D gauge to monitor the sound
'L:Toggle_SW_SND' is the Lvar in the 'dsd_fsx_xml_sound.ini' file used to play the sound file

Code:
(L:Boxcar_ht_zone_1_switch,bool) 0 >
    (L:Boxcar_ht_zone_1_SND,bool) 0 == and
    if{
    1 (>L:Toggle_SW_SND,number)
    1 (>L:Boxcar_ht_zone_1_SND,bool)
    }

This code triggers the switch click on the initial activation but fails to work again after that. I need it to play the sound when the toggle switch is clicked ON and clicked OFF.

Can anyone see where I am going wrong as I am at a loss now as coding really isn't one of my better features!

Thanks.
 
I use temporary variables if I don't have access to the clickspot codes in the modeldef.

Code:
(L:Boxcar_ht_zone_1_switch,bool) (L:Boxcar_ht_zone_1_switch_T,bool) !=
if{ 1 (>L:Toggle_SW_SND,number) (L:Boxcar_ht_zone_1_switch,bool) (>L:Boxcar_ht_zone_1_switch_T,bool) }

This is the way Daniel G. set up custom code in his switch sound packages and I've been using his basic mthodology ever since.
 
Bjoern you are a gentleman, thank you for that code. I dropped it in and it worked perfectly first time! :)

Now I just have to adapt it for all the other custom switches and knobs (I do have access to all the clickspot codes too as I am the modeller so if there is an easier way without the temporary variables please let me know).

BTW I am not familiar with Daniel G. so if you can point me towards his sound packages I would appreciate it as custom sounds are always useful.
 
Daniel Gauthier. Nowadays better known as the guy who does the custom cockpit sounds for the Dakota Project. Look for his stuff on Avsim, as there's a lot of "clicks", "clacks" and "clocks" for cockpit use in his packages.

For an easier solution to trigger the sounds, just add "1 (>L:Toggle_SW_SND,number)" to the end of the switch's clickspot code in the modeldef. This will save yourself the temporary variable.
 
Thanks for the info Bjoern, I will take a look at his stuff on Avsim.

Re. the modeldef code, I like that idea and will implement it as I write new code. I have now added sounds to 95% of the switches on the two main panels and have just a few that are causing issues partly due to other complex code interactions and partly because some are A:Vars and not L:Vars or K:Vars. I will get it sorted though.
 
So I gather it would be helpful if the gauge could respond directly to FS events...
 
Not entirely sure I know what you mean by that Doug. I do have all my switches and knobs (and some levers) assigned to various sounds now (including the ones that were giving me issues earlier).

Some of the problem ones I fixed by actually using the correct variables (DOH! :banghead: ) while a couple of others required the addition of the line of code to the modeldef file and then a re-export (or several) as they wouldn't work via the 2D gauge due to the complexity of the code for those parts.
 
So I gather it would be helpful if the gauge could respond directly to FS events...

With something like a class for events and associated sounds in addition to L: vars?
It would be helpful as it cuts out the middle man in form of a 2D gauge with several "<On><Event>" sections and L: vars.
 
If the thing is to remain as a gauge, then the class route is a no go. You can create the class just fine, but FS will reliably crash on gauge unload. Not really a solution...
I was thinking of specifying the events in the .ini file, just as you do with the LVars. You could conceivably specify three different events - one each for play once, loop, and stop.
It would all be optional of course, but the idea would be that the XML programmer would no longer have to trap events solely to set a sound's control variable.
 
Hi...i am a new user here. I've designed a 3D magneto toggle switch for a 3D cockpit.I wanted to add a sound when the switch is clicked on or off.Below is the sounds code I adapted from some code Henry Vonhinx was kind enough to develop for me to add sounds to the folding wings on the Hellcat I adapted. That's why the term "folding" appears sometimes in the comments. The comments are Henry's.
The first part, related to "pumping sound," is for a hand-operated fuel-pressurizing pump. That sound works as it should, starting and stopping according to the animation of the pump handle.
The second part is for the magneto toggle switch. I have the toggle-switch sliders set at a rate of 0.1 seconds.The sound occurs as it should when the switch is first clicked on. Then, the second time, the sound occurs twice instead of once. This cycle repeats, with one sound for the turn-on-magneto click and two sounds for the turn-off-magneto click.
Let me know if you see how to fix the two-sound problem. Or is there a simpler script to use? I tried something simple, but it totally failed to work.

pcb assembled
 
Last edited:
Your code doesn't show, so try again. Don't forget to post it inside [code][/code] tags.
 
Back
Top