Fangames > Programming Questions

Executing a Code after the Music Stops

<< < (2/2)

Stepcore:
If you don't want it to pick the same song again and again, I would recommend storing all the songs in a data structure and then replacing them with a sound or song you wont play or something when you play them like this:

--- Code: ---songs[0]=paul_chuck;
songs[1]=lucky_star;
songs[n]=n;

--- End code ---
This should only be defined once, because this is where you make the list of all the songs you will be using. You can also use ds_list instead if you want more flexibility.

Then when you want to pick a song from the list and make sure it will only be played once, you can do something like this:

--- Code: ---pickedSong=sound_neverPlay
dice=0
while(pickedSong==sound_neverPlay){
 dice=round(random(6))
 if(songs[dice]!=sound_neverPlay) pickedSong=songs[dice];
}
audio_playmusic(pickedSong)
songs[dice]=sound_neverPlay;

--- End code ---

This way the variable pickedSong will always be the song that is being played. So you can check for when the song is finished by doing this:

--- Code: ---if (!audio_is_playing(pickedSong)){
        //reroll the song here
}

--- End code ---

Of course depending on how your objects and stuff are structured, you might need to make some of them global.
This is how I would do it though. Hopefully I didn't screw it up in the code here.

Tamatou:
Thank you for all the replys guys.
This should be very helpful. I'll post again if I need more help  :atkHappy:

Tamatou:
I'm just doing it with Alarms now. I trigger all the Cherry Patterns with Alarms as well so it seems to be the simplest way.
All the songs are roughly the same lengh (about 30 seconds) so compared to actually programming the cherry patterns this is only a small effort

Navigation

[0] Message Index

[*] Previous page

Go to full version