Disable sound of selected imagebuttons? [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
pastelciel
Regular
Posts: 26
Joined: Sun Nov 23, 2014 8:32 pm
Projects: 【Pitch Black Serenade】
Organization: 97Circle
itch: 97circle
Contact:

Disable sound of selected imagebuttons? [SOLVED]

#1 Post by pastelciel »

I customized the preferences screen in my game and used imagebuttons to activate/deactivate functions.
For example, clicking on the "window" button will turn off the fullscreen mode, and so on. When the game is windowed the "window" button stays selected/hovered in regards to colors while the "fullscreen" button is idle. But whenever I hover or activate the window button I can still hear sounds even if it's selected. How can I disable sounds from buttons when they're "switched on"?

Here's my code:

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav"
Last edited by pastelciel on Fri Sep 21, 2018 12:28 pm, edited 1 time in total.
---------------------------------------------------------------------------------
【Pitch Black Serenade】 demo is out! ⇒ [itch.io]

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Disable sound of selected imagebuttons?

#2 Post by Remix »

Maybe (untested)
hover_sound ("HOVER.wav" if selected else None)
or maybe
hover_sound ("HOVER.wav" if not _preferences.fullscreen else None)
Frameworks & Scriptlets:

User avatar
IrinaLazareva
Veteran
Posts: 399
Joined: Wed Jun 08, 2016 1:49 pm
Projects: Legacy
Organization: SunShI
Location: St.Petersburg, Russia
Contact:

Re: Disable sound of selected imagebuttons?

#3 Post by IrinaLazareva »

pastelciel wrote: Wed Sep 19, 2018 5:22 am Here's my code:

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav"
try

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action Preference('display', 'any window') hover_sound "HOVER.wav" activate_sound "KETTEI.wav"
P.S. It is strange, that this bug is still not corrected...

User avatar
pastelciel
Regular
Posts: 26
Joined: Sun Nov 23, 2014 8:32 pm
Projects: 【Pitch Black Serenade】
Organization: 97Circle
itch: 97circle
Contact:

Re: Disable sound of selected imagebuttons?

#4 Post by pastelciel »

Remix wrote: Wed Sep 19, 2018 6:08 am Maybe (untested)
hover_sound ("HOVER.wav" if selected else None)
or maybe
hover_sound ("HOVER.wav" if not _preferences.fullscreen else None)
Unfortunately, none of them work : (
IrinaLazareva wrote: Wed Sep 19, 2018 7:29 am
try

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" xpos 290 ypos y focus_mask True action Preference('display', 'fullscreen') hover_sound "HOVER.wav" activate_sound "KETTEI.wav" 
imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action Preference('display', 'any window') hover_sound "HOVER.wav" activate_sound "KETTEI.wav"
It's not what I'm looking for, sorry...
---------------------------------------------------------------------------------
【Pitch Black Serenade】 demo is out! ⇒ [itch.io]

User avatar
Remix
Eileen-Class Veteran
Posts: 1628
Joined: Tue May 30, 2017 6:10 am
Completed: None... yet (as I'm still looking for an artist)
Projects: An un-named anime based trainer game
Contact:

Re: Disable sound of selected imagebuttons?

#5 Post by Remix »

I guess _preferences.fullscreen is not evaluating true/false then as the following certainly works:

Code: Select all

screen test_hover_sound():

    default test_val = 0

    vbox:
        textbutton "Test":
            action SetScreenVariable("test_val", test_val+1)
            hover_sound ("audio/auto/default/completion_1_meghan.ogg" if test_val < 5 else None)

        text "[test_val!q]"

label start:

    show screen test_hover_sound

    "..."
So, just amend the conditional and it will work for yours.
Frameworks & Scriptlets:

User avatar
MaydohMaydoh
Regular
Posts: 165
Joined: Mon Jul 09, 2018 5:49 am
Projects: Fuwa Fuwa Panic
Tumblr: maydohmaydoh
Location: The Satellite of Love
Contact:

Re: Disable sound of selected imagebuttons?

#6 Post by MaydohMaydoh »

If you just want to get rid of the sound, shouldn't you just use the selected_ prefix?

Code: Select all

imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav":
    selected_hover_sound None
    selected_activate_sound None

User avatar
pastelciel
Regular
Posts: 26
Joined: Sun Nov 23, 2014 8:32 pm
Projects: 【Pitch Black Serenade】
Organization: 97Circle
itch: 97circle
Contact:

Re: Disable sound of selected imagebuttons? [SOLVED]

#7 Post by pastelciel »

Remix wrote: Thu Sep 20, 2018 2:23 pm I guess _preferences.fullscreen is not evaluating true/false then as the following certainly works:

Code: Select all

screen test_hover_sound():

    default test_val = 0

    vbox:
        textbutton "Test":
            action SetScreenVariable("test_val", test_val+1)
            hover_sound ("audio/auto/default/completion_1_meghan.ogg" if test_val < 5 else None)

        text "[test_val!q]"

label start:

    show screen test_hover_sound

    "..."
So, just amend the conditional and it will work for yours.

Thank you very much! That was exactly the code I was looking for!
I couldn't figure out how to make it work with variables though so instead of those I used the very functions of the buttons.
So that's the code that works for me:

Code: Select all

imagebutton auto "gui/fullscreen_%s.png" action Preference('display', 'fullscreen') hover_sound ("HOVER.ogg" if _preferences.fullscreen == False else None) activate_sound ("KETTEI.ogg" if _preferences.fullscreen == False else None) 
imagebutton auto "gui/window_%s.png" action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound ("HOVER.ogg" if _preferences.fullscreen == True else None) activate_sound ("KETTEI.ogg" if _preferences.fullscreen == True else None)
    
---------------------------------------------------------------------------------
【Pitch Black Serenade】 demo is out! ⇒ [itch.io]

User avatar
pastelciel
Regular
Posts: 26
Joined: Sun Nov 23, 2014 8:32 pm
Projects: 【Pitch Black Serenade】
Organization: 97Circle
itch: 97circle
Contact:

Re: Disable sound of selected imagebuttons? [SOLVED]

#8 Post by pastelciel »

MaydohMaydoh wrote: Fri Sep 21, 2018 6:57 am If you just want to get rid of the sound, shouldn't you just use the selected_ prefix?

Code: Select all

imagebutton auto "gui/window_%s.png" xpos 455 ypos y focus_mask True action [Preference('display', 'window'), SelectedIf(_preferences.fullscreen == False)] hover_sound "HOVER.wav" activate_sound "KETTEI.wav":
    selected_hover_sound None
    selected_activate_sound None
This works too for my issue, thank you very much!
To think it was this simple...! T__T
---------------------------------------------------------------------------------
【Pitch Black Serenade】 demo is out! ⇒ [itch.io]

Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot]