Music reset when leaving game menu

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
Rak01
Newbie
Posts: 1
Joined: Wed Jul 28, 2021 1:05 pm
Contact:

Music reset when leaving game menu

#1 Post by Rak01 »

Hey!
I want to let the player choose the bg music. So here's what I did.

When the game starts, the music starts playing:

Code: Select all

default persistent.bg_music = 1

label start:
    scene bg main

    if persistent.bg_music == 1:
        play music "audio/m1.mp3"

    elif persistent.bg_music == 2:
        play music "audio/m2.mp3"
        
    ...
BG music can be changed on preferences screen:

Code: Select all

## Additional vboxes of type "radio_pref" or "check_pref" can be
## added here, to add additional creator-defined preferences.

vbox:
    style_prefix "radio"
    label _("BG Music")
    textbutton _("Disable") action [SetField(persistent, "bg_music", 0), Stop("music")]
    textbutton _("Music #1") action [SetField(persistent, "bg_music", 1), Play("music", "audio/m1.mp3", False)]
    textbutton _("Music #2") action [SetField(persistent, "bg_music", 2), Play("music", "audio/m2.mp3", False)]
At first this seems to work fine: When I open up the game menu > Preferences and click "Disable", the music stops playing. When I click "Music #1/#2", m1/m2.mp3 starts playing.
However, when I close the game menu, the game will restart the audio file that was initially set to play when the game started.

Why is this happening, what am I doing wrong?

Post Reply

Who is online

Users browsing this forum: Bing [Bot]