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

0 favourites
  • 4 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • 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?

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

  • Okay, and how do I for example: Destroy an object that spawned the object being clicked?

  • Try Construct 3

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

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

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