Adding a sound to skipping?

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
camzgr8game
Newbie
Posts: 12
Joined: Fri Sep 16, 2022 9:32 pm
Contact:

Adding a sound to skipping?

#1 Post by camzgr8game »

Hi all,

I've been trying to add a sound to the skipping function but not had any success. Was hoping someone could give me a hand.

I have tried adding an "on show" statement to the skipping screen, but that didn't seem to work. It the code ran, but no audio came out.

Would be nice as well if when skipping the game chose a random point in the audio file I have to start from as well. My track is a perfect looped track so it would be good to have a little bit of variety by the game choosing a random point in the track, fading in over 0.35 seconds and playing while the player uses skip.

Appreciate the help.
Thanks :)

User avatar
m_from_space
Miko-Class Veteran
Posts: 982
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding a sound to skipping?

#2 Post by m_from_space »

1. Create your own channel for that skipping sound. I suggest using the "voice" mixer, it's not going to get used anyway when skipping, I think.

Code: Select all

init python:
    renpy.music.register_channel("skiploop", mixer="voice", loop=True)
2. Make an addition to the skip_indicator() screen in <screens.rpy>

Code: Select all

screen skip_indicator():
    on "show" action Play("skiploop", audio.MYSOUNDEFFECT)
    on "hide" action Stop("skiploop")
    
    # ...
Since Renpy will stop at the next choice, depending on the amount of dialogue, your sound effect might not have much time for playing, so I don't recommend fading in.

camzgr8game
Newbie
Posts: 12
Joined: Fri Sep 16, 2022 9:32 pm
Contact:

Re: Adding a sound to skipping?

#3 Post by camzgr8game »

I just implemented that, but have the same problem as when I did something similar myself. The code runs, but I don't get any audio. I tried using audio that is just a khtz tone to make sure that its not just playing the first little bit of the file each line that is skipped, but its not that, there is nothing coming out of the speakers.
I used the on show statement on other screens that I have created seems to work, I have a shop set up and it plays the shop theme, but even dropping that code onto the skip indicator doesn't seem to work. Maybe the skip indicator is being called in a different way to regular screens?

User avatar
m_from_space
Miko-Class Veteran
Posts: 982
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding a sound to skipping?

#4 Post by m_from_space »

The skip_indicator() screen is automatically shown (if present) when skipping is happening. It works for me.

Did you change your skip_indicator() screen?

Oh and you said you want some randomness.

Code: Select all

default skip_pos = 0.0

init python:
    def stopSkipping():
        skip_len = renpy.music.get_duration("skiploop")
        if skip_len:
            store.skip_pos = renpy.random.random() * skip_len
        renpy.music.stop("skiploop", fadeout=0.1)
        return

screen skip_indicator():
    on "show" action Play("skiploop", "<from {}>MYSOUND.ogg".format(skip_pos), fadein=0.1)
    on "hide" action Function(stopSkipping)
    
    # ...

User avatar
m_from_space
Miko-Class Veteran
Posts: 982
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding a sound to skipping?

#5 Post by m_from_space »

I just realized that starting from a random position works, but when we reach the end of the sound file (and skipping hasn't stopped yet), it will loop from that random position again, which can be annoying if it was near the end of the track. So we have to create a proper queue first and the channel doesn't have to loop.

Code: Select all

    def startSkipping():
        renpy.music.play("<from {}>MYSOUND.ogg".format(store.skip_pos), channel="skiploop", fadein=0.1)
        renpy.music.queue("MYSOUND.ogg", channel="skiploop", clear_queue=False, loop=True)
        return

screen skip_indicator():
    on "show" action Function(startSkipping)
    on "hide" action Function(stopSkipping)
    
    # ...

camzgr8game
Newbie
Posts: 12
Joined: Fri Sep 16, 2022 9:32 pm
Contact:

Re: Adding a sound to skipping?

#6 Post by camzgr8game »

The only changes I have done to the skip screen where cosmetic, changed the position of it to the other side of the screen. Im using the 8.0.3 renpy, what version are you on?

I just tried both methods on a fresh renpy game and it doesn't work there either?

I did get an error with the store.skip_pos, so I amended that section so that it just plays like default just to see if I could get it working.

User avatar
m_from_space
Miko-Class Veteran
Posts: 982
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding a sound to skipping?

#7 Post by m_from_space »

I'm using 8.1.0, but it shouldn't really matter, but of course you can check out the new version! Can you post your screen please?

If you have problems with store.skip_pos, make sure to define this variable as I posted in my code!

camzgr8game
Newbie
Posts: 12
Joined: Fri Sep 16, 2022 9:32 pm
Contact:

Re: Adding a sound to skipping?

#8 Post by camzgr8game »

Ah yep I had the skip pos commented out. But yes on a fresh project, I still don't get any audio out using this on 8.0.3:

Code: Select all


#path to the skipping audio "audio/skipping.wav"

default skip_pos = 0.0
init python:
    renpy.music.register_channel("skiploop", mixer="voice", loop=True)

    def stopSkipping():
        skip_len = renpy.music.get_duration("skiploop")
        if skip_len:
            store.skip_pos = renpy.random.random() * skip_len
        renpy.music.stop("skiploop", fadeout=0.1)
        return
    def startSkipping():
        renpy.music.play("<from {}>audio/skipping.wav".format(store.skip_pos), channel="skiploop", fadein=0.1)
        renpy.music.queue("audio/skipping.wav", channel="skiploop", clear_queue=False, loop=True)
        return






screen skip_indicator():
    on "show" action Function(startSkipping)
    on "hide" action Function(stopSkipping)
    zorder 100
    style_prefix "skip"

    frame:

        hbox:
            spacing 9

            text _("Skipping")

            text "▸" at delayed_blink(0.0, 1.0) style "skip_triangle"
            text "▸" at delayed_blink(0.2, 1.0) style "skip_triangle"
            text "▸" at delayed_blink(0.4, 1.0) style "skip_triangle"
Its weird, because it runs fine and I don't get any errors, but I just don't know what Im messing up. Im sure its going to be something simple.

Ill try 8.1.0, but it says that on windows that version is still beta?

User avatar
m_from_space
Miko-Class Veteran
Posts: 982
Joined: Sun Feb 21, 2021 3:36 am
Contact:

Re: Adding a sound to skipping?

#9 Post by m_from_space »

Renpy 8.1.0 is in prerelease and will be stable soon. But I tested it with 8.0.3 (fresh project), just included a simple Play() action inside skip_indicator() screen and it works.

1. Make sure in your game preferences the music volumes are set to a volume that you can actually hear (in this case "voice" is important and the main mixer, if affected in any way through your game) - you don't have to use "voice" by the way, you can use "sfx" or "music" too.

2. Make sure your audio file actually plays a sound and Renpy can read it (we had cases in this forum that the files could not get read). Can a normal program like VLC play your audio file?

3. Make sure to understand that skipping has to have time to run long enough to play the sound, since it is automatically stopped when skipping stops. So either hold CTRL or hit TAB once. You could create a loop in your game just for testing skipping (the little triangles have to animate all the time).

edit:

Does this make a notify screen pop up?

Code: Select all

screen skip_indicator():
    on "show" action Function(renpy.notify, "Hello!")
    ...

camzgr8game
Newbie
Posts: 12
Joined: Fri Sep 16, 2022 9:32 pm
Contact:

Re: Adding a sound to skipping?

#10 Post by camzgr8game »

Bingo.
The file doesn't play inside of renpy. Which is super weird. Its gotten the same treatment and source as every other wav file in the game.

I did try using a different track a whileback, but now testing that, that one also doesn't play.

Yep the code works perfect if the audio file is working.

Thanks for the help. Still a bit embarrassed I didn't think to test that the audio was working normally itself.

Thanks :)

Post Reply

Who is online

Users browsing this forum: No registered users