I want to make Press and hold the button to charge the flashlight battery but ı cant

Hello, I want to make a code that will increase the value of the flashlight battery by 1 1 when I hold it down, but I couldn’t do the press and hold event. For example, if the button is right-click, it fills only when I press it, but when I release it, it still continues to fill it, and if I spam the right click, it increases 4 4 or 6 6 instead of increasing 1 1 1.


image

1 Like

Based on what you show as a screenshot, the behavior you list is what I would expect.

Every time the event is started (e.g., you press the button) you are creating a timer. You are never cancelling the timer (meaning it will go on forever, continuing to add to the battery). And since you are adding a new instance of this repeating timer every time you press the button, clicking it multiple times will just start multiple timers.

Look at the input action event you’re implementing; you’ve got something connected to Started, which will fire every time the button is pressed. But you have nothing connected to Completed, so when you release the button it doesn’t bother to do anything.

You could either have a way to cancel your timer and connect that up to Completed, or you could have some code that just did a “has it been 0.5 seconds since my last ‘tick’ of charging, if so, add charge” and connect that to Ongoing so it only happened while the input was ongoing (e.g. held down).

2 Likes

Thanks I understand how to do it