If, Else, Else If etc

Ok, bear with me. I know I’m an idiot, but could somebody shed some light on this.
GDevelop doesn’t seem to have an if else statement in it, I know you can skirt around it in many different ways, but it really doesn’t mesh well with my train of thoughts. I’m running into an issue I can’t seem to be able to fix and it goes something like this:

If you press the button and certain conditions are met, create and object in X and Y and print “It just works!” on screen.
If you press the button and these conditions are not met, don’t create an object in X and Y, but then print “Sixteen times the detail!” instead.

I can’t make this happen. No matter which way I try, the latter option for when the conditions are not met always works as it should, but as soon as the conditions are met it always gives me both results and not the first one alone. I can’t logic around this. I’ve tried several different approaches with different variables and what not, but nothing seems to do the trick.

Programming this in any normal way would be as simple as doing “IF this then this, ELSE do this” and it’s giving me a headache. This has in fact been a pain with everything I do in GDevelop since I started toying around with it. How do I do this?

have you tried using OR plus inverted conditions for the “sixteen times the detail” action?

Something like

  • Button Pressed
    • OR
      • Condition 1 not met
      • Condition 2 not met
      • Condition 3 not met

Hi, I don’t know your event, but did you pay attention to this : the opposite of AND in logic is OR

Given the following conditions :
A=25 AND B=30
The opposite (the else) would be:
A =/ 25 OR B=/30.
(I wrote =/ for “different than”)

Another way to do the else would be to first give the action “Sixteen times the detail!” with no conditions. It would first write it in any case. And then the conditions to write “It just works!”.
In other terms, it will always write the first sentence, except when conditions are met, it changes to the other sentence.


Try something along the lines of:

The variable A is = 25
The variable B is = 30

Create the object "It Just Works!" at X,Y
*Invert* The variable A is = 25
*Invert* The variable B is = 30

Create the object "Sixteen Times The Detail!" at X,Y

You could also create these objects at the beginning of the scene and then hide/show them.

1 Like

Oh, my lord. Thanks for all the replies. I just figured out I am indeed an absolute idiot. I just needed to make the events into sub events for the button press where the correct event then does its thing depending on the set conditions. It’s not exactly an if else statement, but it works the way I wanted.


That would be my way of approaching it. It requires less condition checking, and so less chance of introducing bugs.