Python code in screen causing side-effects? [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
User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Python code in screen causing side-effects? [SOLVED]

#1 Post by DannyGMaster »

This is not exactly an error. You see, I want a screen to play some music when its shown, so I
added something like this:

Code: Select all

screen test:

    python:
         renpy.music.play('audio/Test_01.ogg', loop=True)
        
    add "bg_01"
    add "c_02"
This works, but when the game starts and the main menu is shown, this exact music begins playing. When I show the screen the music simply restarts. I read in the documentation that python code inside screens causes side effects and unexpected behavior, this is probably what they meant, so how can I achieve what I want (having the screen automatically play a music file) without calling it from inside the screen? Do I need to write a function that plays the music and then calls the screen?
Last edited by DannyGMaster on Wed Jun 21, 2017 9:07 am, edited 1 time in total.
The silent voice within one's heart whispers the most profound wisdom.

Andy_kl
Newbie
Posts: 18
Joined: Sun Apr 09, 2017 12:00 pm
Contact:

Re: Python code in screen causing side-effects?

#2 Post by Andy_kl »

Use on "show" action Play(channel, file, selected=None, **kwargs)

https://www.renpy.org/doc/html/screen_a ... io-actions
https://www.renpy.org/doc/html/screens.html#on

Code: Select all

screen test:
    on "show" action Play("audio", 'audio/Test_01.ogg', loop=True)
    #on "hide" action Stop("audio") if music must stop on hide screen
    add "bg_01"
    add "c_02"
If you use music in main menu, change music channel for main menu music and add action Mute for "sounds" and "music" channels.

User avatar
DannyGMaster
Regular
Posts: 113
Joined: Fri Sep 02, 2016 11:07 am
Contact:

Re: Python code in screen causing side-effects?

#3 Post by DannyGMaster »

Andy_kl wrote:Use on "show" action Play(channel, file, selected=None, **kwargs)
Oh!, I didn't know 'on' could be used that way, thanks :D !
The silent voice within one's heart whispers the most profound wisdom.

Post Reply

Who is online

Users browsing this forum: Google [Bot]