Jump to content
The simFlight Network Forums

Start and stop sounds

Recommended Posts

I'm trying to get my head around triggering sounds in FSX & FSUIPC v4.959 with the following .lua script


function playme (path)
			-- do nothing
  			PumpSound = sound.play(path)

-- external toggle switch
if ipcPARAM == 1 then	--	Toggle ON

if ipcPARAM == 0 then	--	Toggle OFF

The sound plays ok, but I cant stop it, nor can I stop it from starting multiple times. what I am missing?

I started with



it plays, but can't be stopped! the .wav file is about 7 seconds long


Link to comment
Share on other sites

23 hours ago, Sim Dave said:

The sound plays ok, but I cant stop it, nor can I stop it from starting multiple times. what I am missing?

You need to refer to the Lua library documentation!  Both sound.query and sound.stop need the REFERENCE to the current sound you started, not the wave path! i.e. in your case PumpSound.



Link to comment
Share on other sites

I have spent hours on something I thought would be a 5-minute job!

having looked again at the log files I have spotted that the sound.query creates an entry 'LUA: Global: Pumpsound = 1' next time the .lua has trigged this increments to 2 and so on. effectively the sound.stop is never going to work the way I'm trying.

Link to comment
Share on other sites

Yes Thomas. The problem is when you toggle the switch the sound starts and .lua finishes, when you toggle the switch off the .lua triggers but it has lost all reference to the sound so can't stop it or starts another instance. Well that is what I think is happening by integrating the sound.query log entry.  I did wonder if I tied the sound start in a loop and then stop the sound and killed the loop with the toggle off might work, but have not gone back to it as it annoyed the hell out of me ;)

Link to comment
Share on other sites

You need to use "listening" code or a loop to keep the lua alive. The best way is a listener, it's all part of the Event Library in the Lua Library.pdf.
The one drawback is that it should be started via the [Auto] section in the .ini . Although it could be started in some other fashion.
There should be no need for a query since the flag  can only be 1 (sound playing) or 0 (sound off).

Maybe this will help - taken from a previous code project (it works) and not tested in this example.



-- Use (LuaSet "lua name") to start the sound and (LuaClear "lua name") to stop it.
-- The parameter for the FSUIPC UI in this code example is zero
-- The lua should be started via the [Auto] section in the FSUIPC#.ini

-- OPTION, adjust path as needed, if wanted
-- sound.path("G:/FSX/Modules")

local flagged = 0

function Sound_Control(flag)
	flagged = ipc.testflag(0)
		 if flagged == true then			
				-- OPTION, play sound once 
				--	MySound = sound.play("ElectricPump.wav")
				-- OPTION, loop the sound continuously until turned off
				 MySound = sound.playloop("ElectricPump.wav")	





Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.