adding sound on imagebuttons

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
searchwindows
Regular
Posts: 86
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

adding sound on imagebuttons

#1 Post by searchwindows »

Code: Select all

init python:
	sfx_directory = "audio/sfx/"
	sfx_cloth = sfx_directory + "cloth_noise.ogg"

screen screen1:
imagebutton auto "images/"redshirt_%s.png":
            focus_mask True
            action [SetVariable("clothes", 2), Hide("purpleshirt"), Show("purpleshirt"), Play("sound", "sfx_cloth")]
Is there anything wrong this code?

game gives no error, but it doesn't actually play the sound when clicked

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

Re: adding sound on imagebuttons

#2 Post by Ocelot »

Is there any reasin you playing sound in action list instad of using activate_sound button property?

Your problem is that Play expects second argument to be string containing path to the sound, not string containing name of variable containing string containing path to the sound. To fix this, use it like:

Code: Select all

Play('sound', sfx_cloth) # Note the lack of quotes in second argument
< < insert Rick Cook quote here > >

searchwindows
Regular
Posts: 86
Joined: Wed Dec 15, 2021 6:17 pm
Contact:

Re: adding sound on imagebuttons

#3 Post by searchwindows »

Ocelot wrote: Thu Jan 13, 2022 3:27 am Is there any reasin you playing sound in action list instad of using activate_sound button property?

Your problem is that Play expects second argument to be string containing path to the sound, not string containing name of variable containing string containing path to the sound. To fix this, use it like:

Code: Select all

Play('sound', sfx_cloth) # Note the lack of quotes in second argument
I did it by using activate_sound. Thanks

Post Reply

Who is online

Users browsing this forum: Google [Bot], RandomHuman64