Is there any way to randomize hover_sound?

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
SandraMJ
Newbie
Posts: 16
Joined: Fri Jun 23, 2017 6:11 am
Completed: The Hayseed Knight
Projects: The Hayseed Knight
itch: sandramj
Contact:

Is there any way to randomize hover_sound?

#1 Post by SandraMJ »

Sorry if this has been answered before, but I've been searching for days and couldn't find a relevant result using styles.

I've got several variations of a button sound I would like to use to prevent navigation from sound annoying, but I can't seem to find a way to make the sound change with each hover.

My code looks like this, and it only seems to generate a first random choice upon start and never making another choice again. Is there any way I could have it cycling through sounds, or at least randomize them?

Code: Select all

#after start label
define button_hover_sounds = ["sfx/hover1.mp3", "sfx/hover2.mp3"]

#button in screens.py
style button:
    properties gui.button_properties("button")
    hover_sound button_hover_sounds[renpy.random.randint(0,1)]
    selected_hover_sound None
Thank you!

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Is there any way to randomize hover_sound?

#2 Post by hell_oh_world »

SandraMJ wrote: Mon Apr 13, 2020 6:40 pm Sorry if this has been answered before, but I've been searching for days and couldn't find a relevant result using styles.

I've got several variations of a button sound I would like to use to prevent navigation from sound annoying, but I can't seem to find a way to make the sound change with each hover.

My code looks like this, and it only seems to generate a first random choice upon start and never making another choice again. Is there any way I could have it cycling through sounds, or at least randomize them?

Code: Select all

#after start label
define button_hover_sounds = ["sfx/hover1.mp3", "sfx/hover2.mp3"]

#button in screens.py
style button:
    properties gui.button_properties("button")
    hover_sound button_hover_sounds[renpy.random.randint(0,1)]
    selected_hover_sound None
Thank you!

Code: Select all

define button_hover_sounds = ["sfx/hover1.mp3", "sfx/hover2.mp3"]
style button:
    properties gui.button_properties("button")
    hover_sound (lambda: renpy.random.choice(button_hover_sounds))()
    selected_hover_sound None
should work. I think.

User avatar
SandraMJ
Newbie
Posts: 16
Joined: Fri Jun 23, 2017 6:11 am
Completed: The Hayseed Knight
Projects: The Hayseed Knight
itch: sandramj
Contact:

Re: Is there any way to randomize hover_sound?

#3 Post by SandraMJ »

Nope, sorry— same result :(

User avatar
hell_oh_world
Miko-Class Veteran
Posts: 777
Joined: Fri Jul 12, 2019 5:21 am
Contact:

Re: Is there any way to randomize hover_sound?

#4 Post by hell_oh_world »

SandraMJ wrote: Tue Apr 14, 2020 7:22 pm Nope, sorry— same result :(
I mean try doing what I shared inline, not by defining styles.
Like...

Code: Select all

style your_button_style:
	align (0.5, 0.5)
	## Do not put the hover_sound property inside a defined style. Do it directly in the screen, perhaps.
	
screen sample:
	button:
		style "your_button_style"
		hover_sound (lambda: renpy.random.choice(your_list_of_sounds))()

Post Reply

Who is online

Users browsing this forum: Princesky