Referencing two instance of the same object type

Get help using Construct 2

Post » Sun Jun 23, 2013 8:54 am

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!
B
4
Posts: 10
Reputation: 220

Post » Sun Jun 23, 2013 9:12 am

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

Evil sprites demo
B
24
S
9
G
7
Posts: 756
Reputation: 7,302

Post » Sun Jun 23, 2013 9:40 am

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:-

https://www.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.
B
4
Posts: 10
Reputation: 220


Return to How do I....?

Who is online

Users browsing this forum: Anonnymitet, Christmas, jorgmaquoi, maxwell88, TELLES0808 and 3 guests