• 🏆 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!

[JASS] Sound not playing

Status
Not open for further replies.
Level 8
Joined
Jul 10, 2008
Messages
353
JASS:
function ActionsOnSelect takes nothing returns nothing
    local sound snd = CreateSound("Buildings\\Human\\HumanTower\\ArcaneTowerWhat1.wav", false, true, true,  10, 10, "DefaultEAXON")
    call SetSoundDuration(snd, GetSoundFileDuration("Buildings\\Human\\HumanTower\\ArcaneTowerWhat1.wav"))
    call SetSoundChannel(snd,1)
    call SetSoundVolume(snd,127)
    call SetSoundPitch(snd,1)
    call SetSoundDistances(snd, 3000, 10000)
    call SetSoundDistanceCutoff(snd, 100000)
    call StartSound(snd)
    call KillSoundWhenDone(snd)
    set snd = null
endfunction
What am doing wrong here? I just can't see anything wrong...
 
Level 8
Joined
Jan 28, 2016
Messages
486
Not entirely sure if this will solve your problem but I'm pretty sure when using Jass sound variables, you have to "preload" the sound by playing it at least once before you actually want to use it but not at map initialistion (doesn't work for both GUI and Jass sounds AFAIK). You might also want to define where the sound is played. For example, if you're trying to play the sound on a unit:
JASS:
function SoundOnUnitExample takes unit singer returns nothing
    local sound audio = CreateSound( "Buildings\\Human\\HumanTower\\ArcaneTowerWhat1.wav", false, false, false, 10, 10, "" )
    call AttachSoundToUnit( audio, singer )
    call SetSoundVolume( audio, 127 )
    call StartSound( audio )
    call KillSoundWhenDone( audio )
    set audio = null
endfunction

There's also a native for positioning a sound at a location using coordinates:
native SetSoundPosition takes sound soundHandle, real x, real y, real z returns nothing
 
Level 8
Joined
Jan 28, 2016
Messages
486
True, I forgot the pitch, distance and cut-off (not sure you need the channel though). All you need to do is attach the sound to either a unit or point using the above natives. For example:
JASS:
function ActionsOnSelect takes nothing returns nothing
    local sound snd = CreateSound("Buildings\\Human\\HumanTower\\ArcaneTowerWhat1.wav", false, true, true,  10, 10, "DefaultEAXON")
    call SetSoundPosition(snd, 0, 0, 0)
    call SetSoundDuration(snd, GetSoundFileDuration("Buildings\\Human\\HumanTower\\ArcaneTowerWhat1.wav"))
    call SetSoundChannel(snd,1)
    call SetSoundVolume(snd,127)
    call SetSoundPitch(snd,1)
    call SetSoundDistances(snd, 3000, 10000)
    call SetSoundDistanceCutoff(snd, 100000)
    call StartSound(snd)
    call KillSoundWhenDone(snd)
    set snd = null
endfunction

Edit: This won't work first time it is run in a map but afterwards, should work as normal. The only way around this issue is to run this once just after the map starts.
 
Last edited:
Status
Not open for further replies.
Top