Referencing a unique object from a function

  • Hello,

    I have several types of bad guy that may be on the screen at once. They belong to a family ("BadGuys"), and there are various conditions under which they may be destroyed. When they are destroyed, we do a few actions (animation, sound, destroy object). So, I'd like to stick those steps in a function and call that function whenever a bad guy meets a condition for destruction.

    What I find is that calling BadGuy.Destroy from a function destroys all the objects in the family, rather than the one that caused the event to trigger. So, I thought I'd pass the BadGuy.UID property in as a param to my function, but I'm not really clear how I can use it on the other end to tell it to only destroy this instance rather than all of them.

    Any help is appreciated!

    Thanks.

  • Can create a condition that compares badguy.health <= 0 this will select only those badguys that need to be destroyed.. then you can spawn a death_anim sprite at its position + destroy the badguy as actions..

    might not be optimal - but you could use the family filtering above

    "badguy.health <=0" destroy badguy

    then for each specific badguy type in the family.. create onDestroyed

    conditions..

    "super_evil on destroyed" spawn super_evil_death_sprite

    any help?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Yes, I think adding an additional condition that says BadGuy.health <= 0 will work. I guess behind the scenes it would be doing a loop over each object in the family and performing the actions if they meet the condition, so not quite as efficient as specifying the UID and avoiding the loop, but I doubt I will see performance issues with this particular game.

    I'd be interested to know if there are other ways to accomplish this (or if I am wrong in my assumption about how it works) since I imagine this is a situation that is fairly common.

    Thanks for your help ;)

  • You'd pass the UID to the function and then in the function have:

    BadGuy: Pick by UID Function.Param(0)

  • You'd pass the UID to the function and then in the function have:

    BadGuy: Pick by UID Function.Param(0)

    Thanks! Guess it needed to be added as a sub-event, but that did the trick!

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