How to play sound on clicking imagebutton?

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
parathingum
Newbie
Posts: 3
Joined: Sat Aug 25, 2018 5:40 pm
Tumblr: paranormal-thingum
Deviantart: paranormal-thingum
itch: paranormal-thingum
Contact:

How to play sound on clicking imagebutton?

#1 Post by parathingum »

hi, i've been working on making the menus in my game, and i'm wondering how i can make imagebuttons play a sound upon being clicked, since the text buttons in my game currently do that just fine but the imagebuttons just don't for some reason despite all my attempts to get them working.

this is the code i've been trying to use for the imagebuttons:

Code: Select all

imagebutton idle "imgbutton/start.png" action Start("") Play(sound, "mouse_click.mp3") xpos 20 -120 focus_mask True at main_btns
this gives me this error:

Code: Select all

I'm sorry, but errors were detected in your script. Please correct the
errors listed below, and try again.


File "game/screens.rpy", line 371: u'Play' is not a keyword argument or valid child for the imagebutton statement.
    imagebutton idle "imgbutton/start.png" action Start("") Play(sound, "mouse_click.wav") xpos 20 -120 focus_mask True at main_btns
                                                                ^

Ren'Py Version: Ren'Py 7.0.0.196
Sat Aug 25 16:46:37 2018
strangely if i put a comma between actionStart and Play like this:

Code: Select all

imagebutton idle "imgbutton/start.png" action Start(""),Play(sound, "mouse_click.mp3") xpos 20 -120 focus_mask True at main_btns
it gives me an entirely different error

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/screens.rpy", line 357, in execute
    screen main_menu():
  File "game/screens.rpy", line 357, in execute
    screen main_menu():
  File "game/screens.rpy", line 370, in execute
    vbox:
  File "game/screens.rpy", line 371, in execute
    imagebutton idle "imgbutton/start.png" action Start(""),Play(sound, "mouse_click.mp3") xpos 20 -120 focus_mask True at main_btns
  File "game/screens.rpy", line 371, in keywords
    imagebutton idle "imgbutton/start.png" action Start(""),Play(sound, "mouse_click.mp3") xpos 20 -120 focus_mask True at main_btns
NameError: name 'sound' is not defined

Windows-8-6.2.9200
Ren'Py 7.0.0.196
software 1.0
Sat Aug 25 16:50:35 2018
from what i can tell, now it's not bothered by trying to use two actions in one button but it's saying the sound channel doesn't exist or something? i'm not sure though i'm really not a coding person and i'm not great at really reading the tracebacks and like...understanding them. i just want the buttons to make clicky sounds ya feel me X(

and while i'm here, here's the code i'm using for the text buttons and another code for the imagebuttons sounds i tried that also isn't working (but isn't crashing the game, which i guess is better?)

Code: Select all

style button:
    properties gui.button_properties("button")
    activate_sound "mouse_click.mp3"
    
style imagebutton:
    activate_sound "mouse_click.mp3"
anyway if anyone could point me in the right direction with this i'd really appreciate it, thank you. knowing me the answer is probably really obvious to anyone who knows more than like two things about coding so i'll take any help i can get

User avatar
vollschauer
Veteran
Posts: 231
Joined: Sun Oct 11, 2015 9:38 am
Github: vollschauer
Contact:

Re: How to play sound on clicking imagebutton?

#2 Post by vollschauer »

Ok... (usually I would recommend using .wav or .ogg, but I guess mp3 patents expired in 2017!?)

The style is:

Code: Select all

style image_button:
    activate_sound "mouse_click.mp3"
or:

Code: Select all

imagebutton idle "imgbutton/start.png" xpos 20 -120 focus_mask True at main_btns:
    action [ Start(""), Play("sound", "mouse_click.mp3") ]
or

Code: Select all

imagebutton idle "imgbutton/start.png" xpos 20 -120 focus_mask True at main_btns:
    activate_sound "mouse_click.mp3"
    action Start("")

Post Reply

Who is online

Users browsing this forum: elcharlo