How to check if an object with 2 instances have the same "Id"?

I have 2 instances of the same object and with the same object var. “Id = 100”
.
I’d like to check if these 2 instances have the same value of “Id” then change their color.
How can I do that?
I need something like if the “Id” of diamond = the “Id” of another diamond from the same object … Then change color for both.
.
Is this possible?

Use a bridge object.
A second object, with the same properties as the first.
Then you have 2 different objects an can compare.

Another method is the use of “pick all” condition or a repeat for each object. Then you have to set scene vars to the object properties and add 1 to a counter to use the next scene var.

1 Like

You can create two object groups, ActiveDiamond and PassiveDiamond, and use them to compare.

do you have a working example of this?
I tried it, and it did not work

setup is, i have 1 single object, and 8 instances, where the 1st row & 2nd row go from id 1 to 4
that object is in group and group2

this is the method i use in my cardgame:

With the help of @arthuro555 I was able to make it work finally.
Here is the script “extension” arthuro made: (arthuro if you want to explain more about it please do).

Basically the issue with comparing directly via an expression is that it will compare an object with itself, making everything always true. To workaround this, I made this little extension condition that does the object selection by itself, in a similar way to the twoListsTest in GDevelops code. To do so, I get the direct reference to the selected objects list by going through eventsFunctionContext.getObjectsList, as getObjects returns a reference to another array.

Then, I use filter to get a list of objects that meet the condition (the condition being that both object have the same variable as string and aren’t the same object), empty the selected object list by setting its length to 0, and finally filling up the picked objects with the objects from the list of objects meeting the criteria (doing objectList = result would not modify the picked objects array, only make the reference refer to another array).

Finally, I give a return value for the condition, which is a check to verify if any objects have met the criteria.

3 Likes

Hmm, actually I don’t.
In a previous topic, I explained how I achieved that using a custom behavior with active/passive object, and someone said it worked likewise with active/passive object groups, but looks like it doesn’t. :thinking: