A common mistake I made when I was a beginner in GDevelop is how to correctly toggle a boolean variable between true and false for case-specific selections.
The challenge arises when attempting to ensure that only one specific block executes based on the current state of the boolean variable. If not managed properly, modifying the boolean variable inside conditional statements can lead to unintended consequences, such as triggering multiple blocks sequentially when only one should execute per cycle.
Expected behavior:
When ‘selector’ is true, specific actions are triggered, and then ‘selector’ should switch to false. Conversely, when ‘selector’ is false, different actions are triggered, and ‘selector’ should toggle back to true. This may ensure that actions alternate based on the current state of ‘selector’ during each cycle (frame).
To try to achieve this behavior (and in lack of a dedicated case-selection block/module for this), usually a beginner will obviously jump to this approach:
Obviously for non-beginners, the problem with this approach is the “False Case” will execute immediately after the “True Case”, since ‘selector’ changing to ‘false’ in the “True Case” immediately triggers it.
This get even worse when the expected behavior is to execute a specific case based on the value of a non-boolean variable, and the executed actions requires to set the stage for the next case changing the ‘selector’ value.
While this may seems a logical setup to achieve this kind of behavior in the eyes of a beginner user, this setup will only trigger a chain reaction that will execute all cases at once.
Of course, you can resolve these issues by introducing an additional boolean variable to track whether a case has been executed in the current cycle or not:
But this is not obvious to a beginner user, the forum is crowded with questions about this same issue, and this would be easily solved with the inclusion of a case-selection block (like “Select Case” or “Choice” blocks).
̵I̵’̵m̵ ̵a̵w̵a̵r̵e̵ ̵a̵ ̵b̵o̵o̵l̵e̵a̵n̵ ̵a̵l̵t̵e̵r̵n̵a̵t̵i̵n̵g̵ ̵a̵c̵t̵i̵o̵n̵ ̵w̵a̵s̵ ̵i̵n̵t̵r̵o̵d̵u̵c̵e̵d̵ ̵a̵t̵ ̵s̵o̵m̵e̵ ̵p̵o̵i̵n̵t̵ ̵t̵o̵ ̵s̵o̵m̵e̵w̵h̵a̵t̵ ̵s̵o̵l̵v̵e̵ ̵t̵h̵i̵s̵ ̵i̵s̵s̵u̵e̵ ̵i̵n̵ ̵b̵i̵n̵a̵r̵y̵ ̵c̵a̵s̵e̵s̵ ̵(̵n̵o̵t̵ ̵i̵n̵ ̵m̵u̵l̵t̵i̵p̵l̵e̵ ̵c̵h̵o̵i̵c̵e̵ ̵c̵a̵s̵e̵s̵,̵ ̵a̵n̵d̵ ̵a̵l̵t̵h̵o̵u̵g̵h̵t̵ ̵i̵t̵ ̵s̵t̵i̵l̵l̵ ̵n̵e̵e̵d̵e̵d̵ ̵a̵ ̵s̵p̵e̵c̵i̵f̵i̵c̵ ̵s̵e̵t̵u̵p̵ ̵t̵o̵ ̵w̵o̵r̵k̵)̵.̵ ̵H̵o̵w̵e̵v̵e̵r̵,̵ ̵i̵t̵ ̵s̵e̵e̵m̵s̵ ̵d̵e̵p̵r̵e̵c̵a̵t̵e̵d̵ ̵s̵i̵n̵c̵e̵ ̵t̵h̵e̵ ̵v̵a̵r̵i̵a̵b̵l̵e̵ ̵s̵y̵s̵t̵e̵m̵ ̵c̵h̵a̵n̵g̵e̵d̵.
Moreover, while it’s possible to resolve this issue with an additional check variable in the setup, I don’t understand why this process is unnecessarily difficult for beginners and time-consuming for advanced users, rather than simply including a ‘Choice’ logical block.
NOTE: please correct me if there is an intuitive, beginner-friendly, and accesible way to achieve this in GDevelop.