Different sounds on "check" textbuttons

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
Pandar
Newbie
Posts: 24
Joined: Sun Dec 08, 2019 1:29 am
Contact:

Different sounds on "check" textbuttons

#1 Post by Pandar »

Hello everyone. I have a textbutton with style_prefix "check" and activate_sound in it. However, I would like to have two different sounds, one when I activate the option and one when I deactivate it. Let me explain better :

Code: Select all

vbox:

        style_prefix "check" 

        textbutton "Unseen text":

            action Preference("skip", "toggle") 
            	
            activate_sound "audio/effects/sound_01.ogg"
When I click on "Unseen text" a check appears next to it and when I click again, it disappears. I would like a sound for when I turn it on and a different one for when I turn it off. Please forgive my English and thanks to anyone who can help me out!

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

Re: Different sounds on "check" textbuttons

#2 Post by m_from_space »

There are different ways of doing it, some examples following. You don't have to write the full file name by the way, if it's a unique name. Renpy automatically detects audio files inside the "audio" folder and puts them into the audio object, stripping the extension (see second example).

Code: Select all

textbutton "Unseen text":

    action Preference("skip", "toggle") 
            	
    if _preferences.skip == "seen":
        activate_sound "audio/effects/sound_01.ogg"
    else:
        activate_sound "audio/effects/sound_02.ogg"
or

Code: Select all

textbutton "Unseen text":
    action Preference("skip", "toggle"), If(_preferences.skip == "seen", Play("sound", audio.sound_01), Play("sound", audio.sound_02))

Pandar
Newbie
Posts: 24
Joined: Sun Dec 08, 2019 1:29 am
Contact:

Re: Different sounds on "check" textbuttons

#3 Post by Pandar »

Hi and thank you! I tried and pasted the code but it gave me this error :

Code: Select all

  File "game/screens.rpy", line 2823, in <module>
    if _preferences.skip == "seen":
AttributeError: 'Preferences' object has no attribute 'skip'
I know I'm probably missing something extremely simple.

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

Re: Different sounds on "check" textbuttons

#4 Post by m_from_space »

Whoops, no it's my fault:

Code: Select all

if preferences.skip_unseen:
    activate_sound "audio/effects/sound_01.ogg"
else:
    activate_sound "audio/effects/sound_02.ogg"

Pandar
Newbie
Posts: 24
Joined: Sun Dec 08, 2019 1:29 am
Contact:

Re: Different sounds on "check" textbuttons

#5 Post by Pandar »

Thank you so much!

Post Reply

Who is online

Users browsing this forum: No registered users