Page 1 of 1

Rererring to particular instances of an object

PostPosted: Sun 10 Feb 2019, 15:55
by Tuomas
Say I have multiple instances of an object on a scene. How would I refer to particular ones if I, for example, wanted to create objects on top of some of them?

The instances in question are created with events.

Re: Rererring to particular instances of an object

PostPosted: Sun 10 Feb 2019, 19:35
by ddabrahim
You can use object linking and object variables to reference specific instances.
What I normally do is at the time I create an instance I also create an object variable called ID to assign a value to it and then check the value of the variable to pick a specific instance.

Code: Select allAt the beginning of the scene : Do = 0 to Variable Counter


And then whenever you create an instance:
Code: Select allCreate object objectName at position X;Y
Do = Variable(Counter) to object variable ID of objectName
Do +1 to Variable Counter


And then to pick an instance:

Code: Select allVariable ID of objectName is = 2 : Do something to that instance

Re: Rererring to particular instances of an object

PostPosted: Sun 10 Feb 2019, 19:41
by BWPanda
Depends how you want to choose the instance to refer to.

For example, if you wanted to pick one by its x/y position, you could add an event where the condition was 'if x/y position is within an object' (or something like that, can't remember the exact name), and then referring to that object in the actions will refer to that specific instance.

Or if you want to refer to an instance when an object collides with it, then use one of the collision conditions.

Basically whichever instances of an object are true for a condition, those instances will be affected by those actions. Hope that makes sense...

Re: Rererring to particular instances of an object

PostPosted: Sun 10 Feb 2019, 20:15
by Tuomas
Thank you both!