0 Favourites

How do I compare two instances of an object?

  • 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. Thanks for your patience.

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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

  • Families makes this easy, but you need the paid version.

  • 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?

  • Make a family with the same objects(s) in it. Check Object overlaps Family, etc.

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)