Page 1 of 1

Renpy.music playing out of nowhere!

Posted: Tue Jan 19, 2021 6:37 am
by KikkomanSoya
I'm having a bit of trouble with renpy.music... During my (unfinished) intro, the music switches to the gitaroo.mp3 file out of nowhere (I've marked the specific time in the code).
I have this simple intro:

Code: Select all

#start
label start:
    $ tod = 4
    $ tow = 1
    $ renpy.music.play("audio/music/sx.mp3", loop=True, fadeout=0.2, fadein=0.2, if_changed=True)
    scene intro0 with slowdis
    "{i}You hear a soft, yet ever so dominant voice calling out to you...{/i}"
    python:
        jname = renpy.input("Your name? ({i}Default: Jimmy.{/i})")
        jname = jname.strip()

        if not jname:
            jname = "Jimmy"

        jcapname = jname.upper()

    qm "[jname]..."
    scene intro1 with slowdis
    qm "Falling asleep during my class, huh?"
    # Music randomly switches right here
    scene intro2 with slowdis
    qm "PLACEHOLDER"
    scene home with vpunch
    j "AH!"
    $ renpy.music.play("audio/music/gitaroo.mp3", loop=True, fadeout=0.2, fadein=0.2, if_changed=True)
    j "{i}NO! Just when I was getting to the good part!{/i}"
    j "{i}God damn, my teacher is beautiful!{/i}"
    j "{i}I wish dreams like those could be real..{/i}"
    jump home
    return
I also have these two:

Code: Select all

#home
label home:
    if tod == 4:
        call screen home_m
    if tod == 3:
        call screen home_d
    if tod == 2:
        call screen home_ev
    if tod == 1:
        call screen home_n
    if tod < 0:
        $ tod = 0
    if tod == 0:
        call screen home_n
    pause
    jump home

Code: Select all

screen home_m():
    $ renpy.music.play("audio/music/gitaroo.mp3", loop=True, fadeout=0.2, fadein=0.2, if_changed=True)
    imagemap:
        ground "scenes/home/home.png"
        use overlay
        imagebutton auto "scenes/home/homesofa_%s.png" focus_mask True
        imagebutton auto "scenes/home/homepc_%s.png" focus_mask True
        imagebutton auto "scenes/home/homedoor1_%s.png" focus_mask True action [Hide("home_m"), Jump("street")]
        imagebutton auto "scenes/home/homedoor2_%s.png" focus_mask True
        imagebutton auto "scenes/home/homebed_%s.png" focus_mask True action [Hide("home_m"), Jump("homebed")]
        imagebutton auto "scenes/0icons/settingsicon_%s.png" focus_mask True
        imagebutton auto "scenes/0icons/mapicon_%s.png" focus_mask True action [Hide("home_m"), Jump("city")]
        imagebutton auto "scenes/0icons/timeicon_%s.png" focus_mask True action [Hide("home_m"), SetVariable("tod", tod-1), Jump("home")]
screen home_d():
    $ renpy.music.play("audio/music/gitaroo.mp3", loop=True, fadeout=0.2, fadein=0.2, if_changed=True)
    imagemap:
        ground "scenes/home/home.png"
        use overlay
        imagebutton auto "scenes/home/homesofa_%s.png" focus_mask True
        imagebutton auto "scenes/home/homepc_%s.png" focus_mask True
        imagebutton auto "scenes/home/homedoor1_%s.png" focus_mask True action [Hide("home_d"), Jump("street")]
        imagebutton auto "scenes/home/homedoor2_%s.png" focus_mask True
        imagebutton auto "scenes/home/homebed_%s.png" focus_mask True action [Hide("home_d"), Jump("homebed")]
        imagebutton auto "scenes/0icons/settingsicon_%s.png" focus_mask True
        imagebutton auto "scenes/0icons/mapicon_%s.png" focus_mask True action [Hide("home_d"), Jump("city")]
        imagebutton auto "scenes/0icons/timeicon_%s.png" focus_mask True action [Hide("home_d"), SetVariable("tod", tod-1), Jump("home")]
screen home_ev():
    $ renpy.music.play("audio/music/gitaroo.mp3", loop=True, fadeout=0.2, fadein=0.2, if_changed=True)
    imagemap:
        ground "scenes/home/home_ev.png"
        use overlay
        imagebutton auto "scenes/home/homesofa_%s.png" focus_mask True
        imagebutton auto "scenes/home/homepc_%s.png" focus_mask True
        imagebutton auto "scenes/home/homedoor1_%s.png" focus_mask True action [Hide("home_ev"), Jump("street")]
        imagebutton auto "scenes/home/homedoor2_%s.png" focus_mask True
        imagebutton auto "scenes/home/homebed_%s.png" focus_mask True action [Hide("home_ev"), Jump("homebed")]
        imagebutton auto "scenes/0icons/settingsicon_%s.png" focus_mask True
        imagebutton auto "scenes/0icons/mapicon_%s.png" focus_mask True action [Hide("home_ev"), Jump("city")]
        imagebutton auto "scenes/0icons/timeicon_%s.png" focus_mask True action [Hide("home_ev"), SetVariable("tod", tod-1), Jump("home")]
screen home_n():
    $ renpy.music.play("audio/music/gitaroo.mp3", loop=True, fadeout=0.2, fadein=0.2, if_changed=True)
    imagemap:
        ground "scenes/home/home_n.png"
        use overlay
        imagebutton auto "scenes/home/homesofa_%s.png" focus_mask True
        imagebutton auto "scenes/home/homepc_%s.png" focus_mask True
        imagebutton auto "scenes/home/homedoor1_%s.png" focus_mask True action [Hide("home_n"), Jump("street")]
        imagebutton auto "scenes/home/homedoor2_%s.png" focus_mask True
        imagebutton auto "scenes/home/homebed_%s.png" focus_mask True action [Hide("home_n"), Jump("homebed")]
        imagebutton auto "scenes/0icons/settingsicon_%s.png" focus_mask True
        imagebutton auto "scenes/0icons/mapicon_%s.png" focus_mask True action [Hide("home_n"), Jump("city")]
        imagebutton auto "scenes/0icons/timeicon_%s.png" focus_mask True action [Hide("home_n"), SetVariable("tod", tod-1), Jump("home")]
I've found that the problem doesn't occur if I remove the "jump home" from the intro, so the problem presumably lies in the second or third script shown. If someone could help, that'd be greatly appreciated!

Re: Renpy.music playing out of nowhere!

Posted: Tue Jan 19, 2021 9:08 am
by Andredron

Code: Select all

screen skip_indicator ():
    on 'show' action Play ('music', 'faster.mp3')
    on 'hide' action Play ('music', 'normal.mp3')

Code: Select all

screen galereya():
    python:
        renpy.music.play("menu.mp3", fadeout=10.0, fadein=15.0)
    frame

Re: Renpy.music playing out of nowhere!

Posted: Tue Jan 19, 2021 9:16 am
by KikkomanSoya
Andredron wrote:
Tue Jan 19, 2021 9:08 am

Code: Select all

screen skip_indicator ():
    on 'show' action Play ('music', 'faster.mp3')
    on 'hide' action Play ('music', 'normal.mp3')

Code: Select all

screen galereya():
    python:
        renpy.music.play("menu.mp3", fadeout=10.0, fadein=15.0)
    frame
Wait, where do I put that?

Re: Renpy.music playing out of nowhere!

Posted: Wed Jan 20, 2021 5:58 am
by Angelo Seraphim
Andredron wrote:
Tue Jan 19, 2021 9:08 am

Code: Select all

screen skip_indicator ():
    on 'show' action Play ('music', 'faster.mp3')
    on 'hide' action Play ('music', 'normal.mp3')

Code: Select all

screen galereya():
    python:
        renpy.music.play("menu.mp3", fadeout=10.0, fadein=15.0)
    frame
Uh... not sure if this is relevant.
-------------------------------------------

@KikkomanSoya
Okay, so, it looks like you're using:

Code: Select all

$ renpy.music.play(...)
... within the screen. No. Don't do that.

Instead, use something like in the screen:

Code: Select all

on 'show' action Play('<audio channel>', '<audio file>')
on 'hide' action Stop('<audio channel>')
This is the safer way. The audio file won't randomly repeat or start over due to the screen refreshing.
In fact, it is advised to not use python or $ in a screen as it is a side effect, hence why you use action instead.

I hope I've understood your problem.

Also, why are you using $ renpy.music.play(...) instead of play music ... in normal renpy script?

Re: Renpy.music playing out of nowhere!

Posted: Thu Jan 21, 2021 4:55 am
by KikkomanSoya
Angelo Seraphim wrote:
Wed Jan 20, 2021 5:58 am
Andredron wrote:
Tue Jan 19, 2021 9:08 am

Code: Select all

screen skip_indicator ():
    on 'show' action Play ('music', 'faster.mp3')
    on 'hide' action Play ('music', 'normal.mp3')

Code: Select all

screen galereya():
    python:
        renpy.music.play("menu.mp3", fadeout=10.0, fadein=15.0)
    frame
Uh... not sure if this is relevant.
-------------------------------------------

@KikkomanSoya
Okay, so, it looks like you're using:

Code: Select all

$ renpy.music.play(...)
... within the screen. No. Don't do that.

Instead, use something like in the screen:

Code: Select all

on 'show' action Play('<audio channel>', '<audio file>')
on 'hide' action Stop('<audio channel>')
This is the safer way. The audio file won't randomly repeat or start over due to the screen refreshing.
In fact, it is advised to not use python or $ in a screen as it is a side effect, hence why you use action instead.

I hope I've understood your problem.

Also, why are you using $ renpy.music.play(...) instead of play music ... in normal renpy script?
Hey! Thanks, I'm gonna try this later today! The reason I was using renpy.music play was that I wanted a music file to keep playing if I go from a scene to another with the same audio, and not reset. Will your method do this, or are there no ways to make that work?