I agree that the better way is to have a dedicated property, rather than detect changes to a whole bunch of properties in -sound.xml. See the -sound.xml file in the Cessna337 for that solution.
As a slight variation on wilbragg's idea, you can also use fgcommands to wrap the existing property-toggle, property-assign, etc.
- Code: Select all
var click = func
{
setprop("sim/sound/click", 1);
var t = maketimer(0.1, func {
setprop("sim/sound/click", 0);
});
t.singleShot = 1;
t.start();
}
var switch = func(command, node)
{
var property = node.getNode("property").getValue();
var oldValue = getprop(property);
fgcommand(command, node);
if (oldValue != getprop(property))
click();
}
addcommand("switch-adjust", func(node) {switch("property-adjust", node);});
addcommand("switch-assign", func(node) {switch("property-assign", node);});
addcommand("switch-toggle", func(node) {switch("property-toggle", node);});
Note that maketimer is preferred to settimer these days.
The switch-toggle, switch-assign can then be used in bindings in the model:
- Code: Select all
<binding>
<command>switch-toggle</command>
<property>controls/switches/battery-master</property>
</binding>
This doesn't have the flexibility of moving the sound in 3D space that wilbragg's solution has, but it is easily reused in checklists, tutorials, etc.