Making a button that counts presses and goes away
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.
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.
- dueceladouce
- Regular
- Posts: 54
- Joined: Sun Dec 27, 2015 7:16 pm
- Location: Michigan
- Contact:
Making a button that counts presses and goes away
I'm trying to make a button that you can press a certain number of times before it deactivates and disappears. I'm sure there's a pretty straightforward method for this, but my coding experience is spotty and haven't been able to brute force it on my own.

Will work in exchange for fight game buddies.
- Ocelot
- Eileen-Class Veteran
- Posts: 1882
- Joined: Tue Aug 23, 2016 10:35 am
- Github: MiiNiPaa
- Discord: MiiNiPaa#4384
- Contact:
Re: Making a button that counts presses and goes away
Code: Select all
# for fancy animation
transform move_it:
xpos 1.0 xanchor 0.0 yalign 0.1
on appear:
xpos 0.95
xanchor 1.0
on show:
linear 1 xpos 0.95 xanchor 1.0
on hide:
linear 1 xpos 1.0 xanchor 0.0
screen secret_button():
default counter = 0
showif counter < 5: # Showif for fancy animation. You can use "if" if no animation is nessesary
textbutton "Press me" at move_it action SetScreenVariable("counter", counter + 1)
label start:
show screen secret_button
' . . . '
'. . .'
'...'
return
< < insert Rick Cook quote here > >
Re: Making a button that counts presses and goes away
A bit expanded sample (you can apply transform either to a button or to the whole screen).
https://www.renpy.org/doc/html/screens. ... -statement
https://www.renpy.org/doc/html/atl.html ... -statement
https://www.renpy.org/doc/html/screens.html#timer
https://www.renpy.org/doc/html/screen_a ... enVariable
https://www.renpy.org/doc/html/config.h ... een_height
https://www.renpy.org/doc/html/style_pr ... rty-xysize
Code: Select all
transform test_button_tr:
on appear:
alpha 0.0
0.5
linear 0.5 alpha 1.0
on show:
zoom .75
linear .25 zoom 1.0 alpha 1.0
on hide:
linear .25 zoom 1.25 alpha 0.0
transform test_screen_tr:
on show:
pos (0, 0)
anchor(1.0, 0.0)
linear 0.5 anchor(0.0, 0.0)
on hide:
linear 0.5 xpos config.screen_width
screen test_button_scr(count=0): # you can pass parameters to a screen
default clicks_left = count
window: # put everything inside a container to apply transform to it
xysize (config.screen_width, config.screen_height) # whole screen size
at test_screen_tr
text "[clicks_left]" align (0.5, 0.05)
showif clicks_left > 0:
textbutton "Click Me!" action SetScreenVariable("clicks_left", max(0, clicks_left - 1)) align(0.5, 0.5) at test_button_tr
else:
timer 1.5 action Hide("test_button_scr") # autohide the screen
# The game starts here.
label start:
"..."
show screen test_button_scr(5)
"... ..."
"?!"https://www.renpy.org/doc/html/atl.html ... -statement
https://www.renpy.org/doc/html/screens.html#timer
https://www.renpy.org/doc/html/screen_a ... enVariable
https://www.renpy.org/doc/html/config.h ... een_height
https://www.renpy.org/doc/html/style_pr ... rty-xysize
- dueceladouce
- Regular
- Posts: 54
- Joined: Sun Dec 27, 2015 7:16 pm
- Location: Michigan
- Contact:
Re: Making a button that counts presses and goes away
That certainly did it. Thank you both very much!

Will work in exchange for fight game buddies.
Who is online
Users browsing this forum: No registered users