| 03-03-2009, 04:16 PM | #1 |
Trigger: Trigger: Trigger: I currently trying to figure out how to make the map play a random music without the need of making a multiple trigger this way. I have browse through the entire tutorial at wc3c, but none of the tutorial cover this part. The tutorial of Play Music by yuripro84 are none accessible as well. Is there any other way to optimize it? |
| 03-03-2009, 04:25 PM | #2 |
That's a very silly approach. What you should do is populate parallel arrays with durations/music paths and then on a single timer executed for <DURATION> seconds, play a random member of the array and re-run the timer for the new <DURATION> number of seconds. |
| 03-03-2009, 04:36 PM | #3 |
Yeah, I know that trigger wasn't good. I was making this sample that suddenly pop up into my mind. I was asking a way to optimize it, can you show me the sample of your optimize? I try use variable, but there is no variable for music. |
| 03-03-2009, 04:44 PM | #4 | ||
Quote:
Quote:
|
| 03-03-2009, 04:50 PM | #5 |
Simply, create a random integer variable, then if its result is 0, set a music and the timer to the duration of that music etc., if its 1, another music etc. and to not make it repeat set a boolean variable that's true when a music has been played, when there's no more music, reset the boolean variables... Something like this should work, I think And as Dusk said, using array variables for the various musics, durations (and I say also for the boolean I suggested you) should make this work easier. |
| 03-03-2009, 06:50 PM | #6 | |
Quote:
The problem was. When I try to make a variable out of import music, it doesn't show the list of import music. |
| 03-04-2009, 11:51 AM | #7 |
I did this small script, but I haven't tested it. You just have to add the music paths with the function AddTrack("Music\\Path") JASS:library RandomMusic initializer init globals private string array Tracks private integer index = 0 private integer last = 0 endglobals private function Loop takes nothing returns nothing local integer i = GetRandomInt(1, index) call PauseTimer(GetExpiredTimer()) loop // to ensure the music selected is not the same as the last played exitwhen index == 1 or i != last set i = GetRandomInt(1, index) endloop set last = i call TimerStart(GetExpiredTimer(), I2R(GetSoundFileDuration(Tracks[last])), false, function Loop) endfunction private function init takes nothing returns nothing if index == 1 then set last = GetRandomInt(1, index) call TimerStart(CreateTimer(), I2R(GetSoundFileDuration(Tracks[last])), false, function Loop) endif endfunction function AddTrack takes string soundfile returns nothing set Tracks[index] = soundfile set index = index + 1 call init() endfunction endlibrary |
