Problem with a condition on multiple objects

I don’t know what category it should be. I was testing how conditions are applied to a group of objects. So I made this small code. It confused me even more.
I created 3 objects with id 1, 2 and 3 and a variable z=120 at the beginning. z is reduced at each cycle. When z becomes smaller than 0 we write its value in the text box, add 120 to z and add 10 to the id.
Adding 10 to the id allows to track how many times the object’s z went below 0. And many times it did but nothing was printed in the text.
My question is how do you explain this? then how does these conditions really work on instances of an object vs objects of a group? thank you

a second test where the only thing I changed was the original z. We see that when object’s z go below 0 at different engine cycle they all appear in the text. Then object 1 does not. Probably because its z goes below 0 at the same engine cycle than another object. But the weird thing is that it still gets its z a plus 120 and its id a plus 10 because it reappears in the text again

much later

An action/condition is only called for every picked object if the object is used as a direct parameter, not if it is used in expressions. Therefore, your action to add text will be repeated for each “text” object, not for each “Group” object. Since there is a single text object, it is executed only a single time, and since expressions can only return a single value from a single instance, only the informations of a single picked instance are added to the text.

On the other hand, your change variable actions afterwards reference the “Group” object directly, and therefore affect all picked instances of “Group”.

Therefore, if multiple instances meet the condition at the same frame, while they’ll all have their z and id increased, only a single one will have its information added to the text object.

You can change this by putting the “Change text” action within a “For each object” event targetting “Group”.

1 Like

thanks it makes sense. Where did you get this explanation? I read all I could in the wiki. Maybe I didn’t notice.

My own experience from using GDevelop and reading its source code

1 Like

Maybe you can confirm my next test below. In the first example I record the order (rank) in which objects z go below 0 outside the “for each” action. When they go below 0 in the same frame they get the same rank. In the second example I include these actions in the “for each” action. And they all get different rank.
From my little knowledge of computer I was excepting that in the first example the rank would all be different because I though everything is done in sequence, not in parallel

. What is the explanation?

The explanation is that, as you said, everything happens in a sequence :stuck_out_tongue: As such, setting the rank will set each picked instances rank to the value of the global variable, before getting to the next step of the sequence, which is adding 1 to the global variable.

On the second event, you repeat the whole code block that sets to the rank and adds 1 to the rank instance per instance, so the rank gets incremented between each setting of the instance rank.

I don’t understand. In the first block, when the condition z<0 is triggered for the 3 objects in the same frame the actions on each object seem to be done in parallel according to the text. Because they all get the same rank. If it was done in sequence, then object 1 would get rank 1, object 2 rank 2 and so on.
Here it’s like the engine reads the condition, put all the objects satisfying the condition into a memory and then applies the action only ounce but for the 3 objects all together. The result is like it was done in parallel.

It might just be a choice of word. I get how the group condition works now. Would it be the same if the condition was on multiple instances of one object?