Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Extended Music Room for Ren'Py

Fully featured music room with improved usability and setup for Ren'Py. · By Feniks

Can the music room continue playing chosen song ingame?

A topic by Jonathan Hawkins created Jan 14, 2024 Views: 115 Replies: 3
Viewing posts 1 to 4

This is an excellent tool you've released! Thanks very much for sharing it. Since you seem very knowledgeable about this, and I am but a novice at best, I was wondering if you might have a simple solution to the following.

I've been fiddling around with my own project, and I started with the official documentation for the music room https://www.renpy.org/doc/html/rooms.html#music-room

I've made a few small, novice-level adjustments so far. But what I am really aiming for is allowing the player to choose what music to listen to, and letting it continue to play until they decide to change songs or turn it off, even when they go back to playing the game.

Here is what I have so far, mostly from the documentation:

########## MUSIC PLAYER SCREEN ##########
init python:
     # Step 1. Create a MusicRoom instance.
     mr = MusicRoom(fadeout=1.0)
     # Step 2. Add music files.
     mr.add("track1.ogg", always_unlocked=True)
     mr.add("track2.ogg", always_unlocked=True)
     mr.add("track3.ogg", always_unlocked=True)
# Step 3. Create the music room screen.
screen music_room:
      tag menu
      frame:
         xpos 320
         ypos 100
         has vbox
         # The buttons that play each track.
         textbutton "Play: Track 1" action mr.Play("track1.ogg")
         textbutton "Play: Track 2" action mr.Play("track2.ogg")
         textbutton "Play: Track 3" action mr.Play("track3.ogg")
         null height 20
         # Buttons that let us advance tracks.
         textbutton "Next Song" action mr.Next()
         textbutton "Previous Song" action mr.Previous()
         null height 20
         # A custom button to stop playing music.
         textbutton "Stop Music" action mr.Stop()
         null height 20
         # The button that lets the user exit the music room. Customized to include a separate function for handling the game menu too.
         if main_menu:
             textbutton "Return" action ShowMenu("main_menu")
          elif not main_menu:
             textbutton "Return" action Return()
      # Start the music playing on entry to the music room.
      # on "replace" action mr.Play() #Commented out intentionally, since it seemed undesirable, but may need to re-enable later.
      # Restore the main menu music upon leaving.
      if renpy.music.get_playing() == "audio/music/track1.ogg":
         on "replaced" action Play("music", "track1.ogg")
      elif renpy.music.get_playing() == "audio/music/track2.ogg":
         on "replaced" action Play("music", "track2.ogg")
      elif renpy.music.get_playing() == "audio/music/track3.ogg":
         on "replaced" action Play("music", "track3.ogg")

The default function for returning to the main menu screen, with the small adjustments I've added to it, works as I had intended. However, when accessing the music room during gameplay via the game menu, and using the Return button to go back to the game, the music stops playing when it leaves the music room.

I understand that it's because the music from script.rpy would take precedence while playing in a normal scenario, but I have not set any music to play in script.rpy in this case, and instead I wish for the music room's current state to carry over into other menus and during gameplay, like it does when going back to the main menu using the "replaced" function (which I admittedly don't understand the significance of.)

If there is a simple and elegant solution (or a messy one is fine too) that you could share to point me in the right direction, I'd appreciate it! 

At any rate, thanks for your time today!

Developer(+1)

Funny you should mention this, as I was planning on putting out an update today that will allow you to get the currently playing track! With this update, instead of default current_track = None in the music room, it'll be default current_track = mr.get_current_song() which will start the music room off with the currently playing track and allow you to easily switch songs etc. It should be out by the end of the day, and I'll put up a devlog about it!

Woah, what are the chances? That's great though! I'm looking forward to being able to try it out.

Testing out the new feature, it seems to work quite well! It feels seamless when starting from music playing in the game, going into the music room from the menu, and then going back to the game, with no interruptions or pauses or anything. Thank you for adding the new functionality!

How could I set it up (or would it be possible) if you changed the music that's playing inside the music room, to go back to the game and keep that music playing? As it works now, the music that was heard during gameplay takes priority.

I'm trying to create this sort of effect:

  • Song 1 (or no song) is playing in the game
  • You access the music room and song 1 keeps playing still (or silence again)
  • You play song 2 in the music room
  • Then you go back to the game, and song 2 keeps playing.

Is there some way to store or reference the track that was playing in the music room last when you return to the game, and have Ren'Py play whatever song it was? It wouldn't even have to be a seamless transition, just having it "remember" and play the last "active" music room song would be great.

I appreciate your time and patience as I try to learn and better understand what is reasonable and what isn't in terms of Ren'Py functionality.