GML Can't play multiple songs in GML

I

Irishes

Guest
Can someone explain the issue with my logic? Currently, When I compile, all of the songs play at once or the same song is just playing strangely. It should add each song randomly to a new array called tracklist and then play each song consecutively.

-- Create Event --
/// Create Music Structure

musicArray[0] = snd_music_battle_for_endor_3;
musicArray[1] = snd_music_battle_for_endor_1;
musicArray[2] = snd_music_battle_for_yavin;
musicArray[3] = snd_music_tie_attack;
musicArray[4] = snd_music_sail_barge_assault_alt;

length = array_length_1d(musicArray);

for(i=0; i< length; i++){
index = choose(random_range(0, length));
trackListArray = musicArray[index];
}

--Step Event--
/// Play Song

i = 0;
currentSong = trackListArray;
audio_play_sound(currentSong, 1, 0);

while(!audio_is_playing(currentSong)){
i++;
currentSong = trackListArray;
audio_play_sound(currentSong, 1, 0);
}
 
K

Kuro

Guest
randomize() or else the other random functions will return the same thing.

Also you seem to be copying over the entire array and trying to play that, rather than pulling out individual songs to play. Or not. It was the wording that threw me. Scratch that. Looks like it should work. Hopefully once the randomizer is fixed.
 
Last edited by a moderator:
I

Irishes

Guest
I just added the randomize to the music controller object. Still getting that strange music sound. It sounds like its being played with a weird feed back. Its very hard to describe. Is there a problem with playing music in a step event?
 
K

Kuro

Guest
I just added the randomize to the music controller object. Still getting that strange music sound. It sounds like its being played with a weird feed back. Its very hard to describe. Is there a problem with playing music in a step event?
Try changing the while to an if. And remove the audio_play_sound that isn't in the if statement.
 
Last edited by a moderator:
K

Kuro

Guest
Just tried it and its still doing it :(
Code:
i = 0;
currentSong = trackListArray;
audio_play_sound(currentSong, 1, 0);
These things are getting performed every step, so start things off in a create event, then change them in the if statement only when they need to be changed. Basically keep all your stuff pertaining to changing tracks to the if statement so its not being run every step.

One thing you might need though is a statment that wraps the i to zero if it increases beyond the array length. but I think the reset to zero every step might have been one source of your problems.
 
Last edited by a moderator:
K

Kuro

Guest
Ahh, I think I've found it now. At create you're copying a particular track to trackListArray. But trackListArray only ever stores one song. So every time you change track you're just changing track to the same song again. In the if statement try fetching a song from musicArray[index] instead. Sorry I missed that for so long. Been trouble shooting touchscreen problems all night so my head was a bit frazzled already. Probably a bad time to be trying to help other people since I'm making a pigs ear out of it.
 
Last edited by a moderator:
I

Irishes

Guest
I just got home from work, gonna give that a try and see what happens. Thanks for all the help.
 
Top