Start and stop sounds with a toggle switch

#1
FSX with FSUIPC
Does anyone have a example how to trigger a sound with a toggle switch and then stop the sound when toggle off?
I played around with this for far to long, before spotting that the .lua loses reference to the sound so cant stop it, but happily starts another one!
Code:
function playme (path)
    if(sound.query(path))
        then
            -- do nothing
        else
              PumpSound = sound.play(path)
          end 
end
 
 
-- external toggle switch
if ipcPARAM == 1 then    --    Toggle ON
    playme("ElectricPump.wav")
end
 
if ipcPARAM == 0 then    --    Toggle OFF
    sound.stop("ElectricPump.wav")
end
The sound file is about 10 seconds long, up to now I have just been using 1 second clicks etc so never needed a stop!
 
Top