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

Sounds not playing the first time

Status
Not open for further replies.

EdgeOfChaos

E

EdgeOfChaos

I'm trying to play a sound. The first time I play it, nothing happens. All following times, it works as expected. Is there some trick to getting it to play the first time correctly?

SoundTools also doesn't work for me, I tried that. It doesn't even play anything.

This is my code for playing a sound:
JASS:
   function playSoundAt takes string path, real x, real y returns nothing
        local sound s = CreateSound(path, false, true, true, 10, 10, "")
        call SetSoundPosition(s, x, y, 0)
        call SetSoundVolume(s, 127)
        call StartSound(s)
        call KillSoundWhenDone(s)
        set s = null
    endfunction
I'm passing it the path to the sound, and I tried a bunch of different settings with is3D and stopping when out of range; nothing helps.
 
Level 13
Joined
May 10, 2009
Messages
868
Yeah, I hate that thing, and I couldn't manage to make it work for its first time either. You can force your map/game to play that sound with its volume set to 0 (just to be sure that no one will hear it every time your game begins). Then, play it normally whenever you need it.
 

EdgeOfChaos

E

EdgeOfChaos

I tried that with this preloader

JASS:
scope Preloads initializer onInit

    private function initSounds takes nothing returns nothing
        local real x = 0
        local real y = 0
        call playSoundAt("Abilities\\Weapons\\Axe\\AxeMissile1.wav",x,y)
        call playSoundAt("Abilities\\Weapons\\ShadowHunterMissile\\HeroShadowhunterMissileHit1.wav",x,y)
        call playSoundAt("Abilities\\Weapons\\BristleBackMissile\\BristleBackMissileHit.wav",x,y)
        call playSoundAt("Abilities\\Weapons\\DruidoftheTalonMissile\\DruidOfTheTalonMissileHit1.wav",x,y)
        call playSoundAt("Sound\\Units\\Combat\\MetalHeavySliceStone1.wav",x,y)
        call playSoundAt("Sound\\Interface\\Warning.wav",x,y)
        call playSoundAt("Abilities\\Spells\\Human\\FlameStrike\\FlameStrikeTargetWaveNonLoop1.wav",x,y)
        call playSoundAt("Abilities\\Spells\\Human\\ThunderClap\\ThunderClapCaster.wav",x,y)
        call playSoundAt("Sound\\Units\\Combat\\RockHeavyBashStone1.wav",x,y)
        call playSoundAt("Abilities\\Spells\\Human\\Flare\\FlareTarget4.wav",x,y)
    endfunction

    private function onInit takes nothing returns nothing
        //preload sounds
        call TimerStart(NewTimer(),1.0,false,function initSounds)
    endfunction
endscope
But it's still not working. How did you make it play once so that it will work the next time?
 
Level 13
Joined
May 10, 2009
Messages
868
That's odd. I just tried your code, and it works perfectly here.

EDIT: I mean, the first time it can't be heard in any way, that's why I "preload" (play) those sound paths before trying to use "for the first time".
 
Last edited:

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
There are a limited number of sound channels available for sounds to play on. If all the appropriate channels are in use a sound will not be played. Just because one cannot hear anything does not mean channels are not in use as very quite sounds could be using them.
 

EdgeOfChaos

E

EdgeOfChaos

It's consistent, though. The first time it's played, no sound. All following times, sound plays. That is, when I have the sound playing code in the correct place (cue during boss attack). When I preload it as above, it still does not play. Is it something to do with playing it at the specified x/y? Any way to make it a global sound instead of point sound?

I'm totally new at sound stuff, and it is very unintuitive. Even the sound tools/utils have no documentation or examples on how to use it, and it didn't work when I did what I figured should work.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Is it something to do with playing it at the specified x/y?
Quite possibly. It will only play the sound if the camera is near the point.
Any way to make it a global sound instead of point sound?
Do not make it a 3D sound and play it as a non 3D sound.

I am guessing the cause is that the game cannot play the sound when requested as it is not loaded. Maybe look at how the campaigns play voice over dialogs since those always played.
 

EdgeOfChaos

E

EdgeOfChaos

I know this is a terrible solution and a hack, but until there's a better way to do this, it's all I got. All my sounds are delayed by 0.15s (which is almost not noticeable; its the lowest I could get it). It's better than no sounds playing the first time; I absolutely need my sounds to run every single time.
JASS:
    struct SoundData
        string path
        real x
        real y
        integer volume
    endstruct
   
    private function playSound takes nothing returns nothing
        local timer t = GetExpiredTimer()
        local SoundData d = GetTimerData(t)
        local sound s
        call ReleaseTimer(t)
        set s = CreateSound(d.path, false, true, true, 10, 10, "")
        call SetSoundPosition(s, d.x, d.y, 0)
        call SetSoundVolume(s, d.volume)
        call StartSound(s)
        call KillSoundWhenDone(s)
        set s = null
        call d.destroy()
    endfunction
   
    private function playSound1 takes string path, real x, real y returns nothing
        local SoundData d = SoundData.create()
        set d.path = path
        set d.x = x
        set d.y = y
        set d.volume = 0
        call TimerStart(NewTimerEx(d),0.01,false,function playSound)
    endfunction
   
    private function playSound2 takes string path, real x, real y returns nothing
        local SoundData d = SoundData.create()
        set d.path = path
        set d.x = x
        set d.y = y
        set d.volume = 150
        call TimerStart(NewTimerEx(d),0.15,false,function playSound)
    endfunction
   
    function playSoundAt takes string path, real x, real y returns nothing
        call playSound1(path,x,y)
        call playSound2(path,x,y)
    endfunction
 

EdgeOfChaos

E

EdgeOfChaos

Tried it. Logic says it should work, but that didn't fix it for some reason.
 
Status
Not open for further replies.
Top