Uninterrupted music after the game ends

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
Ghastly Disco
Newbie
Posts: 2
Joined: Wed Jul 18, 2018 3:01 pm
Tumblr: ghastlydisco
Contact:

Uninterrupted music after the game ends

#1 Post by Ghastly Disco »

Hi everyone!

I'm making my first Renpy game, and I'm trying to have a single piece of music play uninterrupted from the start of the game until the user closes the program. So far I've managed to transition from main menu into the start of the game without the music starting over from the beginning. I've done this by using the queue statement to play the music both at the beginning of the main_menu label and the beginning of the start label.

However, at the end of the game when the user is returned to the main menu, the music starts over. I've tried to work around this by using jump main_menu at the end of my game script instead of return, but this takes me to the pause menu instead of the actual start-of-the-program menu.

How do I prevent the music from restarting at the end of the game?

User avatar
Imperf3kt
Lemma-Class Veteran
Posts: 3792
Joined: Mon Dec 14, 2015 5:05 am
itch: Imperf3kt
Location: Your monitor
Contact:

Re: Uninterrupted music after the game ends

#2 Post by Imperf3kt »

You cannot, at least, not as I understand it.
When the game ends and the main menu is called, Ren'Py is basically restarting.
Warning: May contain trace amounts of gratuitous plot.
pro·gram·mer (noun) An organism capable of converting caffeine into code.

Current project: GGD Mentor

Twitter

User avatar
Per K Grok
Miko-Class Veteran
Posts: 882
Joined: Fri May 18, 2018 1:02 am
Completed: the Ghost Pilot, Sea of Lost Ships, Bubbles and the Pterodactyls, Defenders of Adacan Part 1-3, the Phantom Flyer
itch: per-k-grok
Location: Sverige
Contact:

Re: Uninterrupted music after the game ends

#3 Post by Per K Grok »

Ghastly Disco wrote: Wed Jul 18, 2018 3:37 pm Hi everyone!

I'm making my first Renpy game, and I'm trying to have a single piece of music play uninterrupted from the start of the game until the user closes the program. So far I've managed to transition from main menu into the start of the game without the music starting over from the beginning. I've done this by using the queue statement to play the music both at the beginning of the main_menu label and the beginning of the start label.

However, at the end of the game when the user is returned to the main menu, the music starts over. I've tried to work around this by using jump main_menu at the end of my game script instead of return, but this takes me to the pause menu instead of the actual start-of-the-program menu.

How do I prevent the music from restarting at the end of the game?

One thing you could consider is to have an end screen where the player gets the option to close the game without returning to the main menu or to return to the main menu.

Code: Select all

screen theEnd():
    text "GAME OVER" xpos 100 ypos 175
    textbutton "Quit" action Quit() xpos 100  ypos 200
    textbutton "Main menu" action MainMenu() xpos 100  ypos 220

The player that chose the Quit alternative will have the music playing from start to closing

User avatar
MaydohMaydoh
Regular
Posts: 165
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Uninterrupted music after the game ends

#4 Post by MaydohMaydoh »

You could try using renpy.music.get_playing to get something like something like

Code: Select all

define song = "song.ogg"

label main_menu:
	if song != renpy.music.get_playing():
		play music song
	##rest of code
		
label start:
	##do stuff
	return
Should stop the play statement from restarting the song upon entering the main menu
I think that should work, maybe?

Ghastly Disco
Newbie
Posts: 2
Joined: Wed Jul 18, 2018 3:01 pm
Tumblr: ghastlydisco
Contact:

Re: Uninterrupted music after the game ends

#5 Post by Ghastly Disco »

MaydohMaydoh wrote: Thu Jul 19, 2018 1:52 am You could try using renpy.music.get_playing to get something like something like

Code: Select all

define song = "song.ogg"

label main_menu:
	if song != renpy.music.get_playing():
		play music song
	##rest of code
		
label start:
	##do stuff
	return
Should stop the play statement from restarting the song upon entering the main menu
I think that should work, maybe?
Thanks for the tip! I tried it but it didn't work for me.

I'll just accept this as a limitation of the engine.

User avatar
Saltome
Veteran
Posts: 244
Joined: Sun Oct 26, 2014 1:07 pm
Deviantart: saltome
Contact:

Re: Uninterrupted music after the game ends

#6 Post by Saltome »

Ah Ren'py, this love-hate relationship can't go on like this. Wanted to prove Per K Grok wrong, unfortunately his evaluation is correct, this is a limitation of the engine. As far as I can tell Ren'py's version of pygame doesn't even have the normal mixer functionality.
There is however a way to go around and sneak up on renpy.

Code: Select all

init python:
    import subprocess
    import os
    def resource_path(relative_path):
        try:
            base_path = config.basedir
        except Exception:
            base_path = os.path.abspath(".")

        return os.path.join(base_path, relative_path)
    subprocess.Popen(resource_path("game\\sound_test.exe"))
label start:
    "start"
    "end"
http://www.mediafire.com/file/f731bi34u ... t.exe/file
It needs this file^
Create a new test project and paste this code, then copy the file to its game folder
Hint: q
Deviant Art: Image
Discord: saltome
Itch: Phoenix Start

Post Reply

Who is online

Users browsing this forum: No registered users