• To improve security, we will soon start forcing password resets for any account that uses a weak password on the next login. If you have a weak password or a defunct email, please update it now to prevent future disruption.

Ren'Py imageButton_pressed

City Dom

Newbie
Game Developer
Mar 2, 2024
22
147
Is there a way to have an action performed only while a button is pressed, and have it stop performing once the button is released? I found a couple of methods on the interned but they don't really seem to work.
 

osanaiko

Engaged Member
Modder
Jul 4, 2017
2,149
3,498
From reading these two forum posts:




I think you might be able to use either a CDD or a screen with the "key" keyword detecting mouse events.

So in a Screen, use "key" to detect mousedown, and mouseup, triggering a variable change "pressed=True".
Then in short repeating timer that only runs if the variable is true, call a function.
In your funciton you need to check the mouse position is within your click target, and while it is, keep doing whatever you need the "button pressed" state to do.
When the mouseup event is detected, reset the variable which stops the timer.
You might need some interlocks varaibles or something to handle the mouse position going outside the target area and going back in again.

It's not going to be simple though - Renpy is not primarily designed to be a good platform for realtime event handling (ask me how I know :cry:)
 
  • Haha
Reactions: City Dom

anne O'nymous

I'm not grumpy, I'm just coded that way.
Modder
Respected User
Donor
Jun 10, 2017
10,188
14,917
I think you might be able to use either a CDD or a screen with the "key" keyword detecting mouse events.

So in a Screen, use "key" to detect mousedown, and mouseup, triggering a variable change "pressed=True".
Side note:

This will only works if the said action is a loop, or rely on conditioned additional content. Therefore, if it's handled by a while pressed: or if it can have a if not pressed: [break|return|jump]/if pressed: [do something]. This whatever if it's a handled by an user defined displayable, a function or a label.

And, no, there's no way to stop a code that haven't been designed to be stopped in one of the way above. At least not unless it's a threaded code that you'll forcefully (and dirtily) stop by killing the thread ; something I absolutely not advice for.
 
  • Like
Reactions: City Dom