[SOLVED] Screen, imagebutton and actions

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
runs
Regular
Posts: 41
Joined: Mon Nov 28, 2011 12:31 pm
Location: Spain
Contact:

[SOLVED] Screen, imagebutton and actions

#1 Post by runs » Tue Mar 27, 2018 7:09 am

Image

I want a rose picked by the player, and then a sound effect played. I have the following code in my game:

script.rpy:

Code: Select all

call screen show_item("img/item/rose.png")
screens.rpy:

Code: Select all

#Transforms
transform _show_item:    
    zoom 0.3
    linear 1.0 zoom 0.8

transform fade_item:      
    linear 1.0 zoom 0.85
    additive 0.15

#Screens

screen show_item(_item):
    modal True
    $change_cursor("hand64")
    imagebutton idle _show_item(_item)  hover fade_item(_item) xanchor 0.5 xpos 0.5 yanchor 0.5 ypos 0.65 action [renpy.play("sound/effects/realization.ogg"), Return()]
Without the first action (play a sound) the code works OK, but when I add it, the sound plays three times when the screen is called (why?), and one time when is closed (this is right).

Any tip to solve?

Well, I can solve it simply doing:

Code: Select all

call screen show_item("img/item/rose.png")
play sound effect.realization
But there are two lines in the script. I'd just prefer calling the function.
Last edited by runs on Tue Mar 27, 2018 5:06 pm, edited 1 time in total.

User avatar
Enchant00
Regular
Posts: 133
Joined: Tue Jan 12, 2016 1:17 am
Contact:

Re: Screen, imagebutton and actions

#2 Post by Enchant00 » Tue Mar 27, 2018 10:35 am

Hmm not really sure what could be causing the problem but I think instead of using the renpy.play change it instead to activate_sound. Something like so:

Code: Select all

imagebutton idle _show_item(_item)  hover fade_item(_item) xanchor 0.5 xpos 0.5 yanchor 0.5 ypos 0.65 activate_sound 'sound/effects/realization.ogg' action Return()
I tested this with a texbutton and it seems to work. Not sure if it applies to imagebutton but since both imagebutton and textbutton inherit from button it should theoretically work.

User avatar
runs
Regular
Posts: 41
Joined: Mon Nov 28, 2011 12:31 pm
Location: Spain
Contact:

Re: Screen, imagebutton and actions

#3 Post by runs » Tue Mar 27, 2018 5:05 pm

Oh, thanks, your answer was so sucessful!!!

Post Reply

Who is online

Users browsing this forum: Majestic-12 [Bot], MattMurdock