Adding a sound to CTC [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
BrumaDev
Newbie
Posts: 11
Joined: Wed Apr 28, 2021 9:08 pm
Projects: Occult:Rewrite
itch: brumadev
Location: Brazil
Contact:

Adding a sound to CTC [SOLVED]

#1 Post by BrumaDev » Fri Aug 27, 2021 1:04 pm

Hello!
Let's start with the main question:

How can I add a sound everytime the player clicks to continue, that is, clicks to advance the dialogue?

Basically, that has been answered a couple of times in the past, but the usual answer, which is to add:

Code: Select all

   
    def callbackcontinue(ctc, **kwargs):
        if ctc == "end":
            renpy.music.play("sounds/ctc_click.ogg", channel="ctc", loop=False)
To the code comes with a couple of caveats. For one, as far as I know, if you're already using the callback mechanic to add some kind of beepy voice to the characters that renders this solution unusable since you can't add two callbacks to the same character definition.

Currently, the way I'm doing it is this:

Code: Select all

#note that 'beepyvoice' is a custom audiochannel I created somewhere else.
def playervoice(event, interact=True, **kwargs):
            if not interact:
                return
            if event == "show_done":
                renpy.sound.set_volume(.5, 0)
                renpy.sound.play("audio/sfx/voices/Protag Voice.wav", loop=True, channel='beepyvoice')
            elif event == "slow_done" or event == "end":
                renpy.sound.stop(channel='beepyvoice')
And then defining the characters using this pattern:

Code: Select all

define P = Character(_("You"), callback=playervoice)
I tried a couple of different things, but with my limited coding knowledge, I haven't managed to make it work. Anyone knows how to do it?
Last edited by BrumaDev on Sun Aug 29, 2021 12:44 pm, edited 3 times in total.
Do you like VNs with more gameplay?
Are you interested in the paranormal?
Check out my new project Occult:Rewrite
Image

User avatar
Ocelot
Eileen-Class Veteran
Posts: 1883
Joined: Tue Aug 23, 2016 10:35 am
Github: MiiNiPaa
Discord: MiiNiPaa#4384
Contact:

Re: Adding a sound to CTC

#2 Post by Ocelot » Fri Aug 27, 2021 2:07 pm

You can use config.all_character_callbacks variable to define a list of callbacks which should be run for all characters:

Code: Select all

init python:
    config.all_character_callbacks += [callbackcontinue]
https://www.renpy.org/doc/html/config.h ... _callbacks

You can also create a wrapper class which will store several callbacks and call them in order to get around "one callback per character" limitation
< < insert Rick Cook quote here > >

User avatar
BrumaDev
Newbie
Posts: 11
Joined: Wed Apr 28, 2021 9:08 pm
Projects: Occult:Rewrite
itch: brumadev
Location: Brazil
Contact:

Re: Adding a sound to CTC

#3 Post by BrumaDev » Sun Aug 29, 2021 12:39 pm

Ocelot wrote:
Fri Aug 27, 2021 2:07 pm
You can use config.all_character_callbacks variable to define a list of callbacks which should be run for all characters:

Code: Select all

init python:
    config.all_character_callbacks += [callbackcontinue]
https://www.renpy.org/doc/html/config.h ... _callbacks

You can also create a wrapper class which will store several callbacks and call them in order to get around "one callback per character" limitation
Thanks for the reply! Though I did found a workaround for my problem, this looks like it would be the correct way to do it.

Here's how I managed to do it if anyone's interested:

On the "screens" script there's a section for "say" screen, which displays all the dialogue. Since I already messed around with a lot of stuff there to customize the game, I don't know how the default code looks like, but I've added a couple of lines there to make it so everytime the say screen is hidden, the little ctc sound would play, which essentially is the same as playing it everytime the player clicks to advance the dialogue in my occasion. Here's how that looks.

Code: Select all

screen say(who, what):
    style_prefix "say"

    if not config.skipping and what: ##This keeps the sound from playing when the dialogue is being skipped.
       on 'hide' action Play('sound', 'audio/console/pass.mp3') ## This plays the sound whenever the window is hidden.

    window:
        id "window"
        has vbox
        if who is not None:

            window:
                id "namebox"
                style "namebox"
                text who id "who"

        text what id "what"
 
Do you like VNs with more gameplay?
Are you interested in the paranormal?
Check out my new project Occult:Rewrite
Image

Post Reply

Who is online

Users browsing this forum: Google [Bot]