Trouble with audio that has if_changed attribute

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
trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Trouble with audio that has if_changed attribute

#1 Post by trailsiderice »

Hi, I'm having some trouble getting the if_changed attribute to work.

Basically, I've got my game set up so that starting the game enters a chapter select screen. This chapter select screen is shown inside gameplay, but is set up in such a way that it fools the player into thinking theyre still within the main menu. (This is for two reasons: one, so that I can show game progress on the chapter select screen without having to use persistent data, and two, so that when a player leaves a chapter I can have it take them back to the chapter select screen instead of the main menu.)

The problem arises with my main menu music. I want the main menu music to continue playing on the chapter select screen, but I also want to prevent the music played inside the chapter gameplay from continuing to play on the chapter select menu when the player leaves back to the chapter select menu. To do this, I figured it would be a good idea to, on the chapter select menu label, use if_changed with the play statement, like so:

Code: Select all

label chaptermenu:
    play music "mainmenu.wav" if_changed
    scene black
    call screen chapterselect
    return
unfortunately the if_changed statement doesn't seem to do anything. Starting the game from the main menu still results in the main menu music fading out and restarting. I even tried using renpy.music.play("mainmenu.wav",if_changed=True) but that didn't work either.

I thought I'd try using an if statement with renpy.music.get_playing() but it seems that the value of renpy.music.get_playing() is None when I'm on the main menu. Which confuses me—I'm not sure why the main menu music wouldn't be using the music channel.
Nonetheless I tried something like this:

Code: Select all

label chaptermenu:
    if renpy.music.get_playing() is not None:
        play music "mainmenu.wav" if_changed
    scene black
    call screen chapterselect
    return
but weirdly, it still fades out and back in again. So I'm stumped.

Is there any way to fix this?

trailsiderice
Regular
Posts: 69
Joined: Fri Sep 29, 2023 4:02 pm
Contact:

Re: Trouble with audio that has if_changed attribute

#2 Post by trailsiderice »

Any chance of working around this?

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Trouble with audio that has if_changed attribute

#3 Post by PyTom »

Try 8.2 I think this is fixed there.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot]