Musicplayer (SOLVED)

Started by lapsking, Tue 23/01/2024 09:02:07

Previous topic - Next topic

lapsking

Hi, I have no clue how musicplayer works. It's been an hour I've been searching the forum and looking through manual but still I can't find anything. I want when the player enters a specific room, musicplayer with a list of songs start playing and continue through other rooms and when needed to stop. Any link, hint or tip will be appreciated. Thanks.


eri0o

Is musicplayer some specific old module you are trying to make it work?

Can you explain what have you tried that didn't work, perhaps sharing the code?

lapsking

#3
I want a list of music to play on backgrounds of rooms 12 to 20. Automatically goes to next song and at the end list replays from beginning. If the player leaves these rooms music should stop but if he goes from one of these rooms to another music continues without interruption. Sorry but could I explain myself well or did I just add to the confusion? I have no idea how I should do that or even where to write the code to begin with.

Khris

#4
@lapsking
I wrote a small module: https://drive.google.com/file/d/1AEWB7w4JCiFGLTAKxtfDrrKqaW34KINM/view?usp=sharing

Add tracks in game_start:
Code: ags
  MusicPlayer.AddTrack(aEddie_Vedder___No_Ceiling);
  MusicPlayer.AddTrack(aRodriguez___Forget_It);

Then add this function to your global script (or add the relevant code if it already exists):
Code: ags
function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    if (player.Room >= 12 && player.Room <= 20) MusicPlayer.Play();
    else MusicPlayer.Pause();
  }
}

lapsking

Quote from: Khris on Thu 25/01/2024 12:49:55@lapsking
I wrote a small module: https://drive.google.com/file/d/1AEWB7w4JCiFGLTAKxtfDrrKqaW34KINM/view?usp=sharing

Add tracks in game_start:
Code: ags
  MusicPlayer.AddTrack(aEddie_Vedder___No_Ceiling);
  MusicPlayer.AddTrack(aRodriguez___Forget_It);

Then add this function to your global script (or add the relevant code if it already exists):
Code: ags
function on_event(EventType event, int data) {
  if (event == eEventEnterRoomBeforeFadein) {
    if (player.Room >= 12 && player.Room <= 20) MusicPlayer.Play();
    else MusicPlayer.Pause();
  }
}

Sorry for late reply, I was dealing with a burglery. Thank God my laptop with the game on it wasn't stolen. The code looks exactly what I was looking for. Thank you so much Khris.

lapsking

@Khris

Hi Khris, this module you wrote is great. I was wondering if it's possible to add shuffle to the MusicPlayer module! To make it look less selfish, it might help others too. But if it's a hassle forget it. Thanks.

Khris

Hey, it's pretty simple actually :)

Just redownload the module.
I've added two commands:

Code: ags
  MusicPlayer.Shuffle(bool shuffle); // true / false to turn shuffle on / off
  MusicPlayer.Next(); // skip to next track

lapsking

@Khris
That's great. Working like a charm.  (laugh) Thank you.

Khris

@lapsking I saw you asking about non-blocking code in the AGS 4 thread.

The solution is indeed to simply append "_always" to the repeatedly_execute function's name.
This is basically a bug in my module and I've updated the download accordingly.

lapsking

Yes, thank you Khris :D I added that. My comment in that forum was not just about this module though, was something in general. Like during fade in/fade out which wait blocks the game.

Khris

Yeah, there's a lot of really old, hard-coded behavior in AGS.

Especially the blocking thing can be frustrating, but there's no easy solution for that. You need blocking commands or basic beginner scripts are impossible. However blocking also blocks stuff, which can get in the way of other things.

The fading can be solved with custom code and a black GUI, this way you can make it non-blocking. However this means other commands might now run too soon.

In short: this is unlikely to be "solved" in AGS 4, because there's nothing to solve here. You simply need to learn how to write code for an event-based engine.

Crimson Wizard

#12
Well, particular functions may be added a non-blocking variants (by accepting BlockingStyle argument), at least in theory. FadeIn/Out is one such case.

lapsking

#13
Well, if a black GUI and custom code could solve it, I could try to learn it and maybe I could use SetTimer instead of wait so other commands won't run too soon. But in my case a black GUI won't help, which is getting irrelevant to the topic so I don't dare to get into it. And I think I'm trying to learn a bit more how to write a code for an event-based enginge by asking on the forums and kind people like you guys, as annoying as I can be:D But yeah, I like the idea of taking a coding class :)

EDIT: by the way, in the beginning I said there are different workarounds for each of these blocking/non blocking problems, I suggested a straightforward solution for general use if possible, since I saw others were asking for different workarounds on the forum too. Please pay attention to what I write, thank you.

Khris

Quote from: lapsking on Thu 01/08/2024 15:21:52by the way, in the beginning I said there are different workarounds for each of these blocking/non blocking problems, I suggested a straightforward solution for general use if possible

And I tried to address specifically that by pointing out that there is no easy solve (= straightforward solution for general use) here.
In general you always have to do 1. start [thing] 2. check in repeatedly_execute if [thing] has ended.
And this is not going to change unless AGS Script starts supporting something like Promises.


lapsking

Thanks Khris, for your patience. I'm starting to understand the situation a bit better. From what I gathered, FOR EXAMPLE, there is no way to activate wait command specifically in { } while other commands are busy running in an event-based engine.

SMF spam blocked by CleanTalk