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

Why does this function crash any trigger it is called in?

Status
Not open for further replies.
Level 13
Joined
Oct 18, 2013
Messages
692
Code:
function PlayMusicExt takes string Normal, string External returns nothing
local integer i=0
local string s
       loop
        exitwhen i>11
                if GetLocalPlayer()== Player(i) then
           if GetSoundFileDuration(External) > 0 then
          set s=External
          else
          set s=Normal
          endif
          endif
        call StopMusic(false)  
        call PlayMusic(s)
        set i=i+1
      endloop
endfunction

If I call this using 2 strings (1 of an imported file, the 2nd of another mp3 in a folder players would have to import)

While testing in single player, events after calling this function won't happen, IF Music is off. I'm guessing its something with PlayMusic, just speculation. I might have to disect this function and try to findout what exactly causes this.

edit: I moved these two lines to after the loop, where they should've been.
Code:
        call StopMusic(false)  
        call PlayMusic(s)
and now I don't see the bug anymore. Seems odd, all that was added was those two lines running 10 more times than they otherwise would. I don't know if that would crash the thread (or w.e the name of it is that keeps all trigs running with the cap of ~8192 actions)
 
Last edited:
Level 13
Joined
Oct 18, 2013
Messages
692
Ah, after the first run? So can it be after the loop, or does playing the music have to be in the same bit that I set s?
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
You have to place the music function calls inside the GetLocalPlayer() if statement to be safe from harm.
But you can place it after the loop when every player has got that string.

Just for safety ensurance, set the default value of s to an empty string.
 
Status
Not open for further replies.
Top