Author Topic: Executing a Code after the Music Stops  (Read 2854 times)

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
  • Playstyle: Gamepad
Executing a Code after the Music Stops
« on: November 19, 2015, 07:24:29 PM »
Hello old friends!

I am making a Avoidance Medley with songs in a random order. Kinda like "I Wanna care about the Asteriod River"

Stupid Question, but how do I make the next song play, after the first one finished.
Like I want GM to execute a Code after a song finished that destroys all the cherries and chooses the next song randomly
I know how to make it choose a random song but how do I make it execute a code after a song finished playing?
From Austria with Love <3

lawatson

  • The Kid
  • Posts: 331
  • I do things and I make things.
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
  • Playstyle: Keyboard
Re: Executing a Code after the Music Stops
« Reply #1 on: November 19, 2015, 08:21:21 PM »
try this code out to remove objects:
with playerKiller{
    instance_destroy();
}

just know that unless you use FMod or something you will have to make a whole lot of different sounds for each part of the song. I think I know a way to make it play the correct songs, but that aside, here's the code for stopping sounds:

sound_stop_all();

have fun making this
(click to show/hide)

smoke weed everyday

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
  • Playstyle: Gamepad
Re: Executing a Code after the Music Stops
« Reply #2 on: November 20, 2015, 02:46:33 PM »
Thank you for the Reply

I know how to stop sounds and how to destory instances but what I want is GM to execute a code (or just do something) after a song finishied playing.

I load the songs externally so I use this code:
Code: [Select]
dice = round(random(6))

[code]dice = round(random(6))

if dice = 0
{
audio_playmusic(paul_chuck);
}

if dice = 1
{
audio_playmusic(lucky_star);
}

if dice = 2
{
audio_playmusic(hey_arnold);
}

if dice = 3
{
audio_playmusic(katy_kat);
}

if dice = 4
{
audio_playmusic(super_mario);
}

if dice = 5
{
audio_playmusic(guru_ant);
}

if dice = 6
{
audio_playmusic(andante);
}

of corse alot more songs will be added.
What I want is GM to execute this same code (with slight alterations but that is not the point) again after one song finished playing.

I know I could do this with alarms but that would be a bit exhausting since all the songs are a different lengh (frame count) I just want GM to know when a song is done and make it choose the next one.
From Austria with Love <3

Arclooper

  • Wannabe
  • Posts: 26
  • The plot chickens
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Firefox 42.0 Firefox 42.0
    • View Profile
  • Playstyle: Gamepad
Re: Executing a Code after the Music Stops
« Reply #3 on: November 20, 2015, 03:30:16 PM »
Put the code inside an alarm and inside each if for a song you also put a timer for the same alarm with the size of the song. I mean, it bit be kinda annoying but it's the simplest way.

Though I guess you can also use  if !sound_isplaying(selected song) inside an if for the equivalent dice number for the song in the step event, that should prolly work too, but tbh that sounds like more work than just getting the times, personally :p

Code: [Select]
if dice == 0
{
if !sound_isplaying(paul_chuck)
{dice = round(random(6))}
}

Also I might be wrong but doesn't that code allow it for there to be repeats of the songs?
« Last Edit: November 20, 2015, 03:44:03 PM by Arclooper »

Keygrin

  • Wannabe
  • Posts: 19
  • Keygrin
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Firefox 42.0 Firefox 42.0
    • View Profile
    • Keygrin
  • Playstyle: Keyboard
Re: Executing a Code after the Music Stops
« Reply #4 on: November 20, 2015, 04:54:02 PM »
If I wanted to avoid playing the same song until all the other songs are played...:

Code: [Select]
if dice=0
{
global.song0=1
audio_playmusic(paul_chuck)
}


In some Step Event:
Code: [Select]

if dice=0
if global.song0=1
dice = round(random(6))


You'd want the dice variable to keep randomizing if it's on a value corresponding to the song that was already played. This probably won't work, though.
YouTube Channel

I await the day I die! Living is meaningless to me.

Stepcore

  • Cherry Eater
  • Posts: 87
  • Dreamer of Wizard
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
  • Playstyle: Keyboard
Re: Executing a Code after the Music Stops
« Reply #5 on: November 21, 2015, 01:53:42 PM »
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: [Select]
songs[0]=paul_chuck;
songs[1]=lucky_star;
songs[n]=n;
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: [Select]
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;

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: [Select]
if (!audio_is_playing(pickedSong)){
        //reroll the song here
}

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.
:PogChamp:

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows XP Windows XP
  • Browser:
  • Chrome 46.0.2490.86 Chrome 46.0.2490.86
    • View Profile
  • Playstyle: Gamepad
Re: Executing a Code after the Music Stops
« Reply #6 on: November 22, 2015, 02:43:16 PM »
Thank you for all the replys guys.
This should be very helpful. I'll post again if I need more help  :atkHappy:
From Austria with Love <3

Tamatou

  • Wannabe
  • Posts: 43
  • OS:
  • Windows 7/Server 2008 R2 Windows 7/Server 2008 R2
  • Browser:
  • Chrome 47.0.2526.80 Chrome 47.0.2526.80
    • View Profile
  • Playstyle: Gamepad
Re: Executing a Code after the Music Stops
« Reply #7 on: December 12, 2015, 07:36:44 AM »
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
From Austria with Love <3