Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Playing music 1 after music 2

Author
Message
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 30th Dec 2010 04:50 Edited at: 30th Dec 2010 09:15
I wanted to play a MIDI Sequence as the "intro" which would stop when it ended and allow me to play another MIDI Sequence as the looping main music. So I tried this:


The first/intro music was apparently still playing when I wanted the second/looping music to play, because I had to use STOP MUSIC 1 along with LOOP MUSIC 2 to play the second music.

So I tried setting a timer, adapting a part of TDK's Timer Tutorial:


But that didn't work either. I even tried putting all of the instruments in the looping MIDI Sequence on different channels than the channels the intro MIDI Sequence's instruments were on. Still nothing.

So how do I get the second music to automatically play after the first music?

EDIT: Indented some code to make it easier to read.
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 30th Dec 2010 09:07
I don't think your play music command should be in the loop. That will keeping making dbp play the music so your if condition will never be true. How about this?



Hope this helps.
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 30th Dec 2010 09:23
It still doesn't seem to work. I put the PLAY MUSIC 1 outside the DO-LOOP and it still doesn't play or loop the second music.

I tried changing PLAY MUSIC 1 to LOOP MUSIC 1, and that worked, so why won't it work for the second music?
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 30th Dec 2010 11:01
Hi again. OK I've done a little test and it seems that music playing only return 0 if you've told it not to be playing using commands like stop music. You may have to do something timer based to deal with this.
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 30th Dec 2010 11:13
That's what I was thinking, like I tried to do in my second Code Snippet. This was to be a test of the code to move from the first music to the second music, but in my game, I planned to spawn an object or something and start the music there.

Here's my Code Snippet from my original post:

The only difference in this one is that I updated PLAY MUSIC 2 to LOOP MUSIC 2. It doesn't really make a difference, since the second music never seems to play.
Lucas Tiridath
AGK Developer
16
Years of Service
User Offline
Joined: 28th Sep 2008
Location: Kings Langley, UK
Posted: 30th Dec 2010 12:48
Perhaps your code should go:

IF Elapsed#>9.5

rather than

IF Elapsed#=9.5

as when your code runs, it may never check Elapsed# when it is exactly 9.5.
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 30th Dec 2010 13:40 Edited at: 30th Dec 2010 13:40
You were right, the timer wouldn't equal 9.5, so I changed it to 9. I used the debug tools and found that the Elapsed=(Timer()-T)/1000 needed to be inside the DO-LOOP so it would update.

Here's the finished code:


I tested it and it works now! Thanks for all your help! I really appreciate it.
Dabbler
17
Years of Service
User Offline
Joined: 3rd Mar 2007
Location: Minnesota
Posted: 31st Dec 2010 05:28
The MUSIC PLAYING(n) command does work, but, it only updates during a SYNC.

Try this:



This works just fine on my machine.


Whatever...
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 31st Dec 2010 06:17
Thanks, Dabbler. I tested it and it works fine on my machine too. I think I'll go with this solution, as it means I don't need to worry about timers.
Agent
20
Years of Service
User Offline
Joined: 7th Sep 2004
Location: Sydney, Australia
Posted: 4th Jan 2011 20:00 Edited at: 4th Jan 2011 20:04
Allow me to volunteer my 'jukebox' code that I use in many projects:



You need to set two global values, music and musicvol. Load all your music with the load music command, starting with music number 1, set the music variable to 0 and set the musicvol variable to whatever you prefer from 0 to 100.

Now just call Handle_Music() within your main loop and you'll get jukebox-style play. As each song ends, the next will play, then the next, then the next, and when all of your music has played, it will go back to play the first one, and start through the playlist again.

You should be able to modify this simple function for any purpose.

EDIT: Just an afterthought; note the "if music exist(1)" condition right at the start. This is an error-catcher; if you haven't loaded any music at all, the function will skip all its code and return control straight back to your mainloop without doing anything, preventing the first music playing() command from crashing if there is no music loaded.
Programmer2000
14
Years of Service
User Offline
Joined: 19th May 2010
Playing:
Posted: 4th Jan 2011 22:40
Thank you, Agent. That's a useful function! I might find a way to use this in my game.

Login to post a reply

Server time is: 2024-11-23 03:59:31
Your offset time is: 2024-11-23 03:59:31