Page 1 of 1

Music reset when leaving game menu

Posted: Wed Jul 28, 2021 3:00 pm
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?