[Solved] Click and hold a button

I have a button (a large square) with two animations:
0: Red
1: Green

I want to make it so that when you click and hold the button (i.e. click and hold the mouse down), it changes from red to green. When you release the mouse, it changes back to red. Also, if you move the mouse off the button while holding it down, it should change back to red.

Here’s what I have:

Problems:

  • Releasing the mouse while over the button doesn’t change it to red, it stays green. It’s not until you move the mouse off the button that it changes back to red.
  • Clicking and holding the mouse outside the button, and then moving it over the button, changes the button to green. Ideally it’d only change to green if the mouse was over the button when it was clicked.

Any thoughts on how to fix this?

Ok, this fixes the first problem:

Though I find it weird that the OR conditional didn’t work the same way. What was I doing wrong there?

Still would like to solve the second problem if possible…

OR is a bit special in the way it targets instances. If you’re starting with GDevelop, don’t bother with it. If you want to learn more, you’ll find the details either on the forum or on the GitHub.
Regarding your second issue, do: button is down + trigger once, and sub-condition: cursor is on button.

2 Likes

Thanks @Gruk, that did the trick. Here’s the working code for those interested:

Interesting what you said about OR, I’ll have to research that…
EDIT: This appears to be the explanation of OR @Gruk was referring to: OR operator not working although one condition is valid · Issue #1520 · 4ian/GDevelop · GitHub

2 Likes