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

Sound Thread

Status
Not open for further replies.
Level 4
Joined
Sep 15, 2013
Messages
53
I have some questions regarding the usage of sounds in JASS.

Situation 1 - Lets say I declare a sound handle globally to null. Then on a function a create a sound (ex. 1.mp3) using that sound handle.. I play that sound. Then on another function I create another sound using that same sound handle (ex. 2.mp3) and also play it. Will this cause problem?

Situation 2 - i used the call startsound(s) then immediately followed by call killsoundwhendone(s). I read about it in some thread that it should play alright but then I tested it, it isnt playing. Did i do something wrong?

Situation 3 - If I want to play a sound locally? Should i create the sound inside the getlocalplayer() block then play it? I read about another approach regarding this that it used the same method for special effects. By creating a local string for the sound path to null then setting the sound path inside the getlocalplayer() block then playing the sound outside it. Which should i use?

Thanks to someone who will respond. +Rep
 

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
Situation 1 - Yes. If you don't destroy previous sound handle that would leak. Use StopSound/KillSoundWhenDone function to destroy the previous handle.

Situation 2 - No you didn't. Most probably it's because your sound needs preloading. To preload it, play your sound files using 0 second timer that that (the timer) starts on map's initialization (then immediately stop it so player won't notice). Also try MyPad's suggestion.

Situation 3 - Answered by MyPad.
 
Level 4
Joined
Sep 15, 2013
Messages
53
About situation 2, How do i preload? I cant follow what you said there. Can you explain more? I did it like this.
JASS:
set s=CreateSound("1.mp3"....)
If GetLocalPlayer() == GetOwningPlayer(GetKillingUnitBJ()) then
call StartSound(s)
call KillSoundWhenDone(s)
endif


In situation 3, is it like this?
JASS:
If GetLocalPlayer() == GetOwningPlayer(GetKillingUnitBJ()) then
call StartSound(s)
else
call SetSoundVolume(s,0.00)
endif
 

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
Situation 2 - (just quick example)
JASS:
function preloadSound t nothing ret nothing
set s=CreateSound("1.mp3"....)
call StartSound(s)
call StopSound(s, false, true)
endfunction

function init t nothing ret nothing
call StartTimer(CreateTimer(), 0, false, function preloadSound)
endfunction

Situation 3 -
JASS:
If GetLocalPlayer() == GetOwningPlayer(GetKillingUnitBJ()) then
call SetSoundVolume(s,1.00)
else
call SetSoundVolume(s,0.00)
endif
call StartSound(s)

Just remember, never create/destroy handle locally.
 
Level 4
Joined
Sep 15, 2013
Messages
53
What do you mean create/destroy sound locally? You mean inside the getlocalplayer block? Sorry for the many questions. I needbto clarify things to better understand how to use it. Pardon my ignorance.. What is the difference between stopsound and killsoundwhendone? In what cases do i use each?
 
Level 4
Joined
Sep 15, 2013
Messages
53
So using this:
JASS:
if GetLocalPlayer() == GetOwningPlayer(GetKillingUnitBJ()) then
    call StartSound(s)
endif
Will definitely cause desync right? Or will this work if the sound handle was created globally?
 
Level 4
Joined
Sep 15, 2013
Messages
53
I also want to ask.. I had a sound playing whenever it kills a unit. I had the sound created at map initialization so i can call it whenever i need it. The problem is like this.. So i killed a unit, it will play the sound. The killing event occurs again immediately while the previous sound hasnt ended yet, now the current sound that should play is not playing.. Is there a way around this?
 
Status
Not open for further replies.
Top