[SOLVED] Problem with audio and screens.

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
User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

[SOLVED] Problem with audio and screens.

#1 Post by gas »

Music play in the background from a previous label.

Problem: set the background music from the prefs screen. So you can select a jazzy, rock or fusion theme while you play.

My solution:
Right click - enter setup screen.
Press an arrow button - set an index variable (with a function that cycle values) and play a track accordingly to a list on music channel - so far work fine. A nice jukebox.
Right click to exit the screen - the old first music play again (and I dunno why as it refer to a previous label now expired, no other "play" statement where I return to).

How to have that new music keep playing even if I exit the prefs screen?
I've tried queue reset but baf, does nothing.
Last edited by gas on Mon Mar 13, 2017 2:41 pm, edited 1 time in total.
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

User avatar
PyTom
Ren'Py Creator
Posts: 16093
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: Hey you! Set that track now! Problem with audio and scre

#2 Post by PyTom »

It's difficult. Ren'Py considers the menus to be a different context than the rest of the game, so changes to music from inside the menus will be erased.

What you can do is to have an interact callback that sets the music if not already playing. Something like:

Code: Select all

default persistent.music = "jazzy.opus"

init python:
    def music_callback():
        renpy.music.play(persistent.music, if_changed=True)

    config.interact_callbacks.append(music_callback)
Then in the screen, you can use SetField(persistent, "music", "rock.opus") or whatever.
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

User avatar
gas
Miko-Class Veteran
Posts: 842
Joined: Mon Jan 26, 2009 7:21 pm
Contact:

Re: Hey you! Set that track now! Problem with audio and scre

#3 Post by gas »

I was suspecting the context was guilty :).

Thank you for the reply!
If you want to debate on a reply I gave to your posts, please QUOTE ME or i'll not be notified about. << now red so probably you'll see it.

10 ? "RENPY"
20 GOTO 10

RUN

Post Reply

Who is online

Users browsing this forum: Andredron