Renpy.music playing out of nowhere!

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
KikkomanSoya
Newbie
Posts: 5
Joined: Thu Oct 29, 2020 11:46 am
Contact:

Renpy.music playing out of nowhere!

#1 Post 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!

User avatar
Andredron
Miko-Class Veteran
Posts: 719
Joined: Thu Dec 28, 2017 2:37 pm
Location: Russia
Contact:

Re: Renpy.music playing out of nowhere!

#2 Post 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

KikkomanSoya
Newbie
Posts: 5
Joined: Thu Oct 29, 2020 11:46 am
Contact:

Re: Renpy.music playing out of nowhere!

#3 Post 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?

User avatar
Angelo Seraphim
Regular
Posts: 36
Joined: Tue May 21, 2019 8:00 am
Completed: Enamored Risks (NaNoReNo 2020)
Projects: 616 Charagma
Organization: GLSUoA
Deviantart: glsuoa
itch: glsuoa
Location: London, UK
Discord: Angel Seraph#9599
Contact:

Re: Renpy.music playing out of nowhere!

#4 Post 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?
Image

KikkomanSoya
Newbie
Posts: 5
Joined: Thu Oct 29, 2020 11:46 am
Contact:

Re: Renpy.music playing out of nowhere!

#5 Post 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?

Post Reply

Who is online

Users browsing this forum: Google [Bot]