I’m sharing here this problem just to know if someone is having it and how to solve it.
If the action buttonSingleClicked() is performed on the main Loop() but you dont have any action for that click in the main Loop(), the blink “save” that action and perform it later if he find that action on another loop.
Example:
void loop() {
if (buttonDoubleClicked()) {
secondloop();
}
}
void secondloop() {
if (buttonSingleClicked()){
setColor(RED)
}
}
If I CLICK on the first loop, that action is saved, and if then I do a DOUBLECLICK, the first click is performed in the second loop (not always, but sometimes at random points, that allow the game to do random actions).
I managed to solve it adding an empty action to the main loop: if (buttonSingleClicked()) { }
This is expected. When a button is clicked, an internal flag is set and it is not reset until buttonSingleClicked() is called. I actually wrote about this:
Yea, the semantics here are confusing. What would be better? Having all these state-checking functions unconditionally self clear after each loop() return? Having explicit clear functions?
Or how about going to a pure event-loop model like…
I am not a fan of this one because this would cause clicks that were just missed in a loop call be consumed and then the next loop call would not have it available. This makes Blinks feel unresponsive and make it look like it did not detect a click (I had this issue in Hexxagon and I now only reset button clicks on states that consume them (there are still drawbacks if you are not careful. Like a click in a Blink that happened sometime ago suddenly being registered on a state change).
I am always in favor of flexibility for developers, but I also happen to think that the consume when checking is fine.