How do I compare two instances of an object?

Get help using Construct 2

Post » Sat Jun 07, 2014 6:56 am

Let's say you've picked several instances of Object X which has instance boolean Bool and instance number Num. Let's say we want to pick an instance A of X whose Bool is false and check if it is overlapping any instance of X (let's call it instance B) whose Bool is true. If so then A will set Bool to true and its value of Num to B's value of Num.

Basically my question boils down to: if I'm making comparisons between multiple instances of the same object, how do I distinguish between them? I've read all of Construct 2's documentation and I still can't wrap my head around how the instance-picking works. :roll: Thanks for your patience.
B
12
S
3
Posts: 39
Reputation: 1,001

Post » Sat Jun 07, 2014 8:57 am

The "is overlapping" condition actually picks the overlapping objects itself. So, if you have any pair of overlapping objects, you can have a little function:

objectType is overlapping objectType
---local variables -> objectUID1, objectUID2, objectValue1, objectValue2
---For each objectType
------Store its UID into a local variable
------Store the value to compare into a local variable objectValue
---X objectValue1 = objectValue2
------pick by objectType by UID objectUID1
---------set objectType.valueToChange to objectValue2

This is an abstract kind of example. If you need something more specific, please don't hesitate to ask!
Good luck,
Nathan
B
78
S
22
G
4
Posts: 311
Reputation: 12,739

Post » Sat Jun 07, 2014 2:00 pm

Families makes this easy, but you need the paid version.
ImageImageImage
B
71
S
21
G
232
Posts: 3,695
Reputation: 129,866

Post » Sat Jun 07, 2014 5:43 pm

@Valerien: Ah that's clever, thanks. I think I know how to do this now.

@blackhornet: I have the paid version. How would you implement it with families?
B
12
S
3
Posts: 39
Reputation: 1,001

Post » Sat Jun 07, 2014 6:12 pm

Make a family with the same objects(s) in it. Check Object overlaps Family, etc.
ImageImageImage
B
71
S
21
G
232
Posts: 3,695
Reputation: 129,866

Post » Sun Jun 08, 2014 6:54 am

@blackhornet @seven : the idea is effectively to use a family as your object type. Just be aware that "is overlapping" picks any list of overlapping objects. Thus, it may return 3, 4 or more objects at once. In that case, you can just generalize so that if one instance has its bool to true, all of the others are set to true. Or you can feed them into an array and send them to the function by pairs.
B
78
S
22
G
4
Posts: 311
Reputation: 12,739


Return to How do I....?

Who is online

Users browsing this forum: David181, jorgmaquoi, MPPlantOfficial, unicornspitfire and 28 guests