• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Need help with multiple sounds

Status
Not open for further replies.
Level 5
Joined
Jul 15, 2012
Messages
101
Greetings to you all,

I recently tried to make a sound play whenever you do some action (for one example: click the left arrow button). I expected it to play everytime it was triggered, but it seems that the sound waits till it's over and only then it can be played again.

  • Sound - Play MetalHeavySliceFlesh3 <gen>
How do I allow the same sound to be played before it's end?
 
Level 7
Joined
Dec 28, 2014
Messages
83
The only way to play a sound multiple times in a row is to use custom scripts with the function:

vJASS:
function PlaySound takes string soundName returns nothing

  • Sound On Click
    • Events
      • Player - Player 1 (Red) issues Mouse Down event
    • Conditions
    • Actions
      • Custom script: call PlaySound("Sound\\Units\\Combat\\MetalHeavySliceFlesh3.wav")
This method does not require you to create a sound variable in the Sound Editor but it requires you to type it's file name.

To know the path of the file name, create a new sound variable in the Sound Editor, right-click the sound variables then Edit Sound Variable.

You will see something like this:

upload_2018-6-10_0-26-42.png


The path for MetalHeavySliceFlesh3.wav is Sound\Units\Combat\.

In custom scripts, file paths are required to have a double backslash "\\".
 
Level 5
Joined
Jul 15, 2012
Messages
101
Thanks Glint!

There still seems to be a small gap where the sound is not there but it will do.

Will the sound leak? I need to destroy it because it is now local, not glocal, do I?

EDIT: Also, any chance you are in knowledge of what the JASS script looks like if I want the sound to be played on unit?
 
Last edited:
Level 7
Joined
Dec 28, 2014
Messages
83
Well this how the function works:
vJASS:
function PlaySound takes string soundName returns nothing
    local sound soundHandle = CreateSound(soundName, false, false, true, 12700, 12700, "")
    call StartSound(soundHandle)
    call KillSoundWhenDone(soundHandle)
endfunction
It creates a sound handle, plays the sound and destroys it once it is done. It will definitely not leak.

EDIT: Ops, I forgot to read the last sentence. You have to create your own function for that.
 
Last edited:
Level 5
Joined
Jul 15, 2012
Messages
101
  • Custom script: call PlaySoundAtPointBJ( gg_snd_MetalHeavySliceFlesh2, 100, GetUnitLoc(udg_UNIT), 0 )
I found the function, but my complete lack of JASS knowledge prevents me from using the function. The function works but now it is as it was previously, the sound cannot be played multiple times at one. I need to use some sort of sound handle or whatever (sound soundHandle, real volumePercent, location loc, real z). I suppose I will do some learning, seems interesting.
 
Status
Not open for further replies.
Top