StopSound doesn't support EmitSound().
What is another way to play a sound and stopping it after a few seconds? It just loops the sound nonstop.
I've tried
[CODE]local snd = CreateSound( ent, "ambient/alarms/siren.wav" )
snd:Play()
timer.Simple( SoundDuration("path/to/the.wav"), function(snd) if snd then snd:Stop() snd = nil end end, snd )
[/CODE]
Yet it doesn't work. Any ideas?
1) You forgot how to use timers.
2) You forgot that SoundDuration doesn't work.
3) StopSound only works for sound scripts, not direct paths.
[QUOTE=Robotboy655;46696574]1) You forgot how to use timers.
2) You forgot that SoundDuration doesn't work.
3) StopSound only works for sound scripts, not direct paths.[/QUOTE]
1. There's nothing wrong with the timer.
2. OK.
3. I know it doesn't work with sound paths. I was aware of that, also I've mentioned it.
Your timer is very wrong.
Your timer:
[lua]timer.Simple( SoundDuration("path/to/the.wav"), function(snd) if snd then snd:Stop() snd = nil end end, snd )[/lua]
Corrected:
[lua]
timer.Simple( SoundDuration("path/to/the.wav"), function() if snd then snd:Stop() snd = nil end end )[/lua]
The snd as the function argument is useless, you put a comma there for some reason and added an extra end.
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/timer/Simple]timer.Simple[/url]
[editline]12th December 2014[/editline]
Oh wait, you used snd as an argument after the end, that's also wrong.
Solved. Cheers.
Sorry, you need to Log In to post a reply to this thread.