Local debounce not working

Your solution in this case is not to implement the debounce variable “locally” (as in initializing inside the click function), but to create 4 separate debounce variables to control each of the buttons individually.

The reason your code did not work, and as others were explaining, is that you are initializing a new variable, ‘localDebounce’ to false each time the button is clicked (because it is inside the function). The function won’t remember the value next time it runs if the variable is defined inside of it.

If you want a variable that retains its value, it needs to be placed outside of the function. To make it work individually for each button, you recognized that using the same variable will not work.

So, you will need 4 debounce variables, one for each button.

TLDR: create 4 variables, one for each button. Each variable should be defined outside of the function, not inside.

3 Likes

Basically, what I said 269261928377812736 times.

2 Likes

Move all local localDebounce = false outside of function. Because they are set to false again whenever function is fired, therefore leading to it being always false.

image

3 Likes

I already did that, however it still doesn’t seem to work.

1 Like

Okay, I realized I made a pretty dumb mistake, it works now. Thanks yall!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.