How to play a "Bad End Music" in main menu? [SOLVED]

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
ourdecemberdreams
Regular
Posts: 58
Joined: Sat Apr 15, 2017 3:26 pm
Projects: The Last December
Tumblr: ourdecemberdreams
Deviantart: ourdecemberdreams
itch: ourdecemberdreams
Contact:

How to play a "Bad End Music" in main menu? [SOLVED]

#1 Post by ourdecemberdreams »

Heyy,

So I've tried looking around online for an answer, but I can't find what I'm looking for and I'm getting desperate, so please help me T^T

I understand that I have to change the following line to get a main menu music to play when the users enter the main menu, but what I want is when the user finished the game and got a bad end, another music file will play instead of the default.

Code: Select all

define config.main_menu_music = "main-menu-theme.ogg"
I've tried defining a new variable in the "options.rpy" file (not sure if I'm doing this right):

Code: Select all

define menu_music = "main-menu-theme.ogg"
define bad_music = "bad-menu-theme.ogg"
And then tried adding it into the menu screen (I've removed the excess codes):

Code: Select all

screen main_menu:
    tag menu

    if badEndings == 3:
        use bad_menu
    else:
        use normal_menu
        
        
screen normal_menu():
    tag menu

    style_prefix "main_menu"
    
    play main_music
    
    
screen bad_menu():
    tag menu

    style_prefix "main_menu"
    
    play bad_music
But that doesn't work. I've tried to do it like changing the background images as well, but nope, it doesn't work either because apparently "play" can't be used in if else statements?

Code: Select all

    if badEndings == 3:
        play bad_music
    else:
        play main_music


SEND HELP PLEASE, THANKS :D
Last edited by ourdecemberdreams on Tue Jan 16, 2018 10:50 am, edited 1 time in total.

User avatar
mitoky
Veteran
Posts: 316
Joined: Sat Feb 07, 2015 9:12 pm
Projects: The Purring Demon's Love, circus eterie
Contact:

Re: How to play a "Bad End Music" in main menu?

#2 Post by mitoky »

Make the badEndings a persistent and try this:

Code: Select all

init python:
    if persistent.badEndings == 3:
        config.main_menu_music = "bad-menu-theme.ogg"
    else:
        config.main_menu_music = "main-menu-theme.ogg" 
The only problem is that the music wont actually change until you restart the game (aka close and open it). I dont know how to fix that though. If anyone knows how (or knows a better method) feel free to correct me!

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

Re: How to play a "Bad End Music" in main menu?

#3 Post by Imperf3kt »

Here's how to do it so it changes when you return to the main menu. Note that main_menu and game_menu are not the same thing, but you can apply this trick to both if you want. Simply change the <name>_menu as appropriate.

First, default all variables in script.rpy somewhere before label start:

Code: Select all

default m_menu_music = "main-menu-theme.ogg"
default persistent.bad_end = 0
Next, somewhere in your script, adjust the bad_end variable. Most suitably, at the end of a bad end.

Code: Select all

    "You died."
    "Bad End."
    $ persistent.bad_end += 1
    return
Next, under options.rpy, ensure you have the following:

Code: Select all

define config.main_menu_music = "main-menu-theme.ogg"
In screens.rpy, find the main_menu screen:

Code: Select all

screen main_menu():

    ## This ensures that any other menu screen is replaced.
    tag menu

    style_prefix "main_menu"

    add gui.main_menu_background
    
And add the following:

Code: Select all

    if persistent.bad_end == 3:
        $ m_menu_music = "bad-menu-theme.ogg"
    else:
        pass
    on "show" action Play("music", m_menu_music)
If I missed anything let me know.
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

ourdecemberdreams
Regular
Posts: 58
Joined: Sat Apr 15, 2017 3:26 pm
Projects: The Last December
Tumblr: ourdecemberdreams
Deviantart: ourdecemberdreams
itch: ourdecemberdreams
Contact:

Re: How to play a "Bad End Music" in main menu?

#4 Post by ourdecemberdreams »

Omg thank youuuuu guys! The code works!

Post Reply

Who is online

Users browsing this forum: Google [Bot]