0 Favourites

Referencing two instance of the same object type

  • I'm sure there is an easy way to do this but I haven't seen it and not been able to find it in my searching unfortunately. I'm looking to reference two of the same object.

    So for example lets say I have created 10 instances of an object, I want to loop through those 10 objects and changes a variable on each of them but reference another instance of the object. So lets say we do something like this (writing in Sudo code)

    On Ball Collision (We'll call this #1)

        For Each Ball (We'll call this #2)

            Ball#2.height = Ball#2.height - Ball#1.height

    You can see I'm trying to reference 2 objects which are both called ball, but not sure how I would be able to do this. Another example of this would be I had several buckets and I wanted to move the contents of the buckets down the line

    For Each Bucket (#1)

        For Each Bucket (#2)

            If Bucket#2.id = Bucket#1.id + 1

                 Bucket#1.contents = Bucket#2.contents

    A way around this would be to store an the instance of the object in a variable. When I try and search for this all I'm able to find is information on instance variables, and while they are helpful they aren't exactly what I'm looking for ;)

    I hope this makes sense, and hopefully someone will be able to help me out with this. Any help I'd be able to get would be greatly appreciated!

  • Here is an example that involves handling collisions between two instances of same object:

    Evil sprites demo

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • So it looks like the best way to do things is to use "pick instance" which is effectively what I was looking for. I can see some situations where that might a little tricky still, but I think in most cases I was looking for this should help. Thanks for that!

    For people who search for this you can find more information on it here:-

    scirra.com/manual/124/system-conditions

    It's a system condition. Another system I'm thinking of playing with storing the UIDs in an array and then using this to reference the different objects.

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