• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!

How to use sounds?

Status
Not open for further replies.
How do you really play sounds in warcraft?
It always seem to bug for me, if i do it it GUI with "play sound" then "destroy sound", the sound only plays the first time the trigger is fired, if even then.

I then tried to make a jass function to handle it, it looked like this:
JASS:
function PlaySoundLocal takes player p, string path returns nothing
local sound snd = CreateSound(path, false, false, false, 10, 10, null)
call StartSoundForPlayerBJ(p, snd)
call KillSoundWhenDone(snd)
set snd = null
endfunction

And fired with:
JASS:
call PlaySoundLocal(GetOwningPlayer(GetBuyingUnit()), "Sound\\Interface\\ClanInvitation.wav")

But again, it doesn't play.
So how do you play sounds correctly?

EDIT: The error was in the rest of my trigger, the sound now plays well in the jass function.
Though i would like to know, does it leak?
Since i create the sound for all players, plays it for one, then deletes it once it's done playing for that player?
 
Last edited:
Level 13
Joined
Nov 22, 2006
Messages
1,260
Well, I used to destroy sounds in GUI too, but then when I started learning JASS I noticed that there's only one global sound which can be started and stopped...weird. I don't know what is that destroy action in GUI for. Don't take my word :p
 
Apparently Destroy Sound fixes the leak of the sound. To be honest, i recently found out sounds do leak (in the thread "Things that leak"). Why this action could be useful? Instead of doing this: "Custom script: call StopSound(bj_nightAmbientSound, true, true)" (which disables the night sound, the "wolf" one, when time gets 18.00), you could instead go to the Sound Editor, select the sound and use "Sound - Destroy DuskWolf <gen>", for full GUI language ;)
 
Status
Not open for further replies.
Top