(Solved) If _ Else event

Hello everyone. How to create an event in the editor?
If a
Else
Waiting for help.

There is no concept of “Else” in GDevelop.

You would just set up an event with inverse conditions.

So event 1 would be:
“If Object A’s X position is > 100 || Do whatever”

Event 2 (Your else) would be:
“If Object A’s X position is > 100 (inverted) || Do whatever” (or you could just do < 100)

Hi!
I want to 1 and 2 click on the exchange of attributes between instances


Yes, that won’t work (even if the engine has an “else”). Every event is processed every frame, from top to bottom.

Right now what you have will lead to both subevents occurring. This is because your first event occurs when click = 1, then you set click to 2. That then means the second subevent would occur immediately in the same frame, since it processes next in the event list, and click is now not = 1.

I’d recommend a few things:

  1. Add “Trigger once” to your top event conditions. Otherwise it’ll process every frame you leave the mouse button down.
  2. Add some kind of toggle so that the event logic only occurs once until you release the mouse button. Some examples on toggle state logic are available here: How to toggle states using Variables [GDevelop wiki]

As far as the swapping of objects states, I can’t provide much guidance there, but you’ll probably need an intermediary variable of some kind to store the state of the swapping items.

I use a workaround to manage ELSE:
1: condition1:null - event1: global variable glElse=T
2: condition1:your condition - event1: do something
2 event2:global variable glElse=F
3:condition1: if glElese=T-event: do something

I think the solution in this case is simpler :

  1. Add a trigger once to the first event in the screen shot.
  2. Swap the two sub events.

I agree, but I thought they were going to make it potentially be any of the tiles.

I was working off the assumption that elem_click was the indicator of which tile it was going to be swapped with (and therefore there could increment to a much higher number) which is why a toggle state was going to be needed.

If it isn’t incremental in that way, 100% agreed with your method.

1 Like

Hi guys!!!
Your advice helped to go in the right direction.
This is how I did my algorithm.
For testing, made a container from text objects



I think the question is resolved

2 Likes