Is there a variable that you can save soundtracks to? I'm implementing a media player in my map, and I want to give the ability to skip songs (or go back to them), pause, and play. There's a display in the bottom right for all of this. The buttons are working, and I've found my problem to be that I can't save which soundtrack is currently playing, in order for me to detect when it ends.
As long as your soundtrack is not flagged as "continuous" and all of your sound tracks for your soundtrack is in that one soundtrack (cues) you can try this method:
Import sounds, create "sounds" for each of them under data editor, import all as cues into soundtrack (and unflag "continuous" in that soundtrack)
Trigger time!
The way I did it, I created four variables (besides my dialog buttons for the media player): "currentSoundtrack", "maxSoundTrackIndexes", "PauseValue" and "clicked." The soundtrack in my sample is called "MyMusic." (if you download and utilize my map to test, the soundtracks are two back-and-forth dialogues for some of my other maps, clearly not musical soundtracks)
Besides the map initialization (wherein the dialog is created and I call the trigger "Play Soundtrack") there are two triggers: one to handle the soundtrack, the other to handle your dialog buttons.
The "Play Soundtrack" trigger looks like this:
PlaySoundtrackEventsLocalVariablesConditionsActionsGeneral-Repeat(Actions)foreverActionsGeneral-If(Conditions)thendo(Actions)elsedo(Actions)If------- If someone is trying to get to a cue that is a negative number, set them to the first track.currentSoundtrack<=0ThenVariable-SetcurrentSoundtrack=0ElseGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfcurrentSoundtrack>maxSoundtrackIndexesThen------- If we are at the end of the soundtrack, start from beginning.Variable-SetcurrentSoundtrack=0Else------- Play the soundtrack "MyMusic" with the cue number (aka track number) "currentSoundtrack"Sound-PlayMusicMyMusic(AnySoundtrackIndex)for(Allplayers)(withcuecurrentSoundtrack)andDoNotmakedefaultSound-WaitforMyMusicplaybacktoend------- The following is a condition to alleviate a "skip" issue due to a "trigger calling a trigger" and the programming doing some funny things.General-If(Conditions)thendo(Actions)elsedo(Actions)Ifclicked>=1ThenVariable-Setclicked=0ElseVariable-ModifycurrentSoundtrack:+1
Here's the dialog code:
DialogButtonHandlerEventsDialog-AnyDialogItemisusedbyPlayerAnyPlayerwitheventtypeClickedLocalVariablesConditionsActions------- Actions for "Pause" Btn:General-If(Conditions)thendo(Actions)elsedo(Actions)If(Useddialogitem)==PauseBtnThenGeneral-If(Conditions)thendo(Actions)elsedo(Actions)IfPauseValue==0ThenVariable-SetPauseValue=1Dialog-SetPauseBtntextto"Resume"for(Allplayers)Dialog-SetPauseBtntooltipto"Resume Soundtracks"for(Allplayers)Sound-PauseMusicsoundtrackfor(Allplayers)(AfterFading)General-SkipremainingactionsElseVariable-SetPauseValue=0Dialog-SetPauseBtntextto"Pause | |"for(Allplayers)Dialog-SetPauseBtntooltipto"Pause Soundtrack"for(Allplayers)Sound-UnpauseMusicsoundtrackfor(Allplayers)(AfterFading)General-SkipremainingactionsElse------- Actions for "Next" Btn:General-If(Conditions)thendo(Actions)elsedo(Actions)If(Useddialogitem)==nextBtnThenVariable-Modifyclicked:+1Variable-ModifycurrentSoundtrack:+1Else------- Actions for "Previous" Btn:General-If(Conditions)thendo(Actions)elsedo(Actions)If(Useddialogitem)==previousBtnThenVariable-Modifyclicked:+1Variable-ModifycurrentSoundtrack:-1ElseTrigger-StopallinstancesofPlaySoundtrackTrigger-RunPlaySoundtrack(CheckConditions,Don't Wait until it finishes)
If any of this doesn't make sense, let me know, I'll explain why - hopefully you can edit this to your needs. I thought this was an easy five-minute answer, and I've spent nearly three hours arguing with the triggers to get it to work right! :D
PS, the fourth "soundtrack" / cue does have a swear word in it, you are warned! Good luck!
@Blixster: Go
My one concern with this (with a quick overview) is that this won't work for each player. See, I'm trying to make each player have their own media player, and they control THEIR music, not that of other people (unlike some other maps, like Runling Run).
Could this be done with "sounds" instead of "soundtracks"? There IS a variable implemented for currently playing sound.
EDIT: This is driving me insane. Now, it's playing two songs at once. Maybe you can take a look at the map. The triggers are the Music trigger in the "Core" folder, and every trigger in the Music folder. Be sure to test the map first to make sure you're aware of what's ACTUALLY happening. It's probably some simple thing I'm missing but I've been searching for two days, and it's still hidden to me.
make an integer variable like the first guy did, and give it an array and then make it like: if variable x[player value] then u have it for each player
What I've done is put your audio in a soundtrack file itself and I'm still coming up with the triggers... It might already work, the only problem I think I have now is it won't auto-play, and if you try to make it, it gets angry :-\
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
Is there a variable that you can save soundtracks to? I'm implementing a media player in my map, and I want to give the ability to skip songs (or go back to them), pause, and play. There's a display in the bottom right for all of this. The buttons are working, and I've found my problem to be that I can't save which soundtrack is currently playing, in order for me to detect when it ends.
Is there any way to do this?
@HeroLief: Go
As long as your soundtrack is not flagged as "continuous" and all of your sound tracks for your soundtrack is in that one soundtrack (cues) you can try this method:
The way I did it, I created four variables (besides my dialog buttons for the media player): "currentSoundtrack", "maxSoundTrackIndexes", "PauseValue" and "clicked." The soundtrack in my sample is called "MyMusic." (if you download and utilize my map to test, the soundtracks are two back-and-forth dialogues for some of my other maps, clearly not musical soundtracks)
Besides the map initialization (wherein the dialog is created and I call the trigger "Play Soundtrack") there are two triggers: one to handle the soundtrack, the other to handle your dialog buttons.
The "Play Soundtrack" trigger looks like this:
Here's the dialog code:
If any of this doesn't make sense, let me know, I'll explain why - hopefully you can edit this to your needs. I thought this was an easy five-minute answer, and I've spent nearly three hours arguing with the triggers to get it to work right! :D
PS, the fourth "soundtrack" / cue does have a swear word in it, you are warned! Good luck!
@Blixster: Go My one concern with this (with a quick overview) is that this won't work for each player. See, I'm trying to make each player have their own media player, and they control THEIR music, not that of other people (unlike some other maps, like Runling Run).
Could this be done with "sounds" instead of "soundtracks"? There IS a variable implemented for currently playing sound.
EDIT: This is driving me insane. Now, it's playing two songs at once. Maybe you can take a look at the map. The triggers are the Music trigger in the "Core" folder, and every trigger in the Music folder. Be sure to test the map first to make sure you're aware of what's ACTUALLY happening. It's probably some simple thing I'm missing but I've been searching for two days, and it's still hidden to me.
Uploaded to Mediafire because it's too big to upload here. Link Removed: http://www.mediafire.com/?yzmgz02p5dsbk1b
@HeroLief: Go
lol I had mine playing two songs at once too - and I'll take a look, let you know if I figure anything out.
make an integer variable like the first guy did, and give it an array and then make it like: if variable x[player value] then u have it for each player
Any luck so far?
@HeroLief: Go
What I've done is put your audio in a soundtrack file itself and I'm still coming up with the triggers... It might already work, the only problem I think I have now is it won't auto-play, and if you try to make it, it gets angry :-\