How do I refer to the object I'm using in event/condition?

Get help using Construct 2

Post » Fri Apr 15, 2016 6:08 pm

Hi, I'm new to this forum this is my first topic..

I don't understand how can I detect for example which object is being clicked by the mouse, so I can do stuff with that object in the 'Actions'.. I'm talking about more objects of the same type, If I 'Destroy' that object, all objects of that type disappear, how do I destroy this object I'm using in the conditions?
B
18
S
6
Posts: 138
Reputation: 1,643

Post » Fri Apr 15, 2016 6:31 pm

When you use the action "on object clicked" it will "pick" only the object you clicked on.

For your destroying example, you need to specify which object is going to get destroyed, by picking it first.

it can be the one you clicked on,
the one with the highest Y value
the one with the lowest opacity.

however you want to pick it

so for example

On Mouse "enemy" is clicked -> destroy enemy

or

Enemy.Opacity < 50 -> destroy enemy (this will only destroy and enemy with less than 50 opacity.)

The event "picks" and the action runs the corresponding code based on what you picked.
B
83
S
39
G
15
Posts: 984
Reputation: 16,741

Post » Fri Apr 15, 2016 6:47 pm

Okay, and how do I for example: Destroy an object that spawned the object being clicked?
B
18
S
6
Posts: 138
Reputation: 1,643

Post » Fri Apr 15, 2016 7:13 pm

Firstly, this is a very important read, specifically in regards to picking: https://www.scirra.com/manual/75/how-events-work

For your specific question, here is one method - I would use UID:

Add an instance variable to the SpawnedObject "SpawnedFrom". When you spawn the object, also set the variable to SpawnerObject.UID. Now every SpawnedObject has a reference to which SpawnerObject it came from.

On clicked SpawnedObject
Pick SpawnerObject by Unique ID SpawnedObject.SpawnedFrom - Destroy SpawnerObject

Manual entry for UID - https://www.scirra.com/manual/130/common-features
Mistakes were made.
B
49
S
24
G
107
Posts: 1,581
Reputation: 60,303


Return to How do I....?

Who is online

Users browsing this forum: ramyaswetha and 5 guests