Not sure what you mean, we can do “if A do B else C” in language programming, it’s same here.
In JavaScript, if you do:
let a = 0;
let b = 0;
if (condition) {
a = 1 ;
} else {
b = 1
}
Then at the end, either a or b is equal to 1.
In GDevelop, if I do:
Conditions: Position X of Object1 is <100
Then Actions:
Set Object1 to be red,
Do =1 to scene variable A
Else Actions:
Set Object1 to be green
Do =1 to scene variable B
Let’s consider that there are some “Object1” that are verifying the condition. In this case, they should be made red. But what about the other (that have position X greater or equal to 100)?
- First solution, as you explained: “With else we need always thinking with instances”. So we run the “Then actions”, and some objects are set to red. Then we run the “Else actions”, and some objects are set to green.
Sounds good BUT now we have the scene variable A and the scene variable B that are set to 1. This is not a else!
- Second solution, we can say “If the conditions are true, run the “Then actions” as usual. If they are false, then run the “Else actions””. In this case, at the we either scene variable A or scene variable B that is set to 1 - not both
BUT this is almost useless, because your “Else actions” will only run if not a single Object1 has a position < 100.
Conclusion: seems that, as you said “With else we need always thinking with instances”. So let’s go for solution 1… but as explained strictly speaking this is not a “else”. We should name it otherwise. Something like:
Conditions: Position X of Object1 is <100
Then Actions:
Set Object1 to be red,
Do =1 to scene variable A
Actions for the other objects:
Set Object1 to be green
Do =1 to scene variable B
Then we need use “for each” loop in GD.
You’re right that in your example, we need the for each. I would like to avoid having the user to do this.
So can we find a solution that:
- Avoid having the user to use for each
- Can turn a bunch of “Object1” red and green according to their position?
In other words:
Problem: Should “else” be exclusive (run only some actions) or always run both actions list?
Ok, now there is another problematic use case where I would like your view:
In a traditional event, if I do:
Conditions:
Scene variable C is =1
Position X of Object1 is <100
Then Actions:
Set Object1 to be red
Do =1 to scene variable A
It’s straighforward:
- If scene variable C is equal to 1, then we look at which object1 position are under 100. Finally, we run the actions to set them red. And we set the scene variable A to 1. Easy!
- If scene variable C is equal to 0, then we stop everything and go to the next event. This is very useful to avoid running useless conditions. Also we don’t run the actions, so scene variable A stays to 0.
Sounds good? So now let’s use this with or “Else” event instead:
Conditions:
Scene variable C is =1
Position X of Object1 is <100
Then Actions:
Set Object1 to be red,
Do =1 to scene variable A
Actions for the other objects:
Set Object1 to be green
Do =1 to scene variable B
- If scene variable C is equal to 1, then we look at which object1 position are under 100. We then run the “Then Actions”, we set these object1 to red and variable A to 1. We then run the “Actions for the other objects”: the object1 that have not been picked previously are now set to be green and variable B is set to 1.
(So both variable A and variable B are set to 1. A bit weird but why not, we decided it’s ok).
- Now if Scene variable C is equal to 0. What should we do??
- We can run the “Else actions”. But this means that ALL object1 will be set to green, as not a single one has been filtered by the second condition because the second condition was NOT run. I guess we agree that having all the Object1 set to green is weird…
- Or we can say “in this case, run all the conditions” Even if some conditions are false… But this means that if Scene variable C is equal to 0, then all actions will STILL be run, so variable A and variable B will be set to 1.
It’s a bit like before: seems like the “else event” we’re discussing about is either not adapted to objects or not adapted to variables What do you think?
In other words:
Problem: Should else run all the conditions, or stop at the first condition that is false?