Referencing a unique object from a function

Get help using Construct 2

Post » Sun Feb 03, 2013 7:52 pm

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.
B
3
Posts: 7
Reputation: 289

Post » Sun Feb 03, 2013 8:14 pm

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?matt752013-02-03 20:20:43
B
6
G
2
Posts: 37
Reputation: 1,499

Post » Sun Feb 03, 2013 8:27 pm

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 ;)
B
3
Posts: 7
Reputation: 289

Post » Sun Feb 03, 2013 9:15 pm

You'd pass the UID to the function and then in the function have:
BadGuy: Pick by UID Function.Param(0)
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,000

Post » Sun Feb 03, 2013 10:14 pm

[QUOTE=ramones] You'd pass the UID to the function and then in the function have:
BadGuy: Pick by UID Function.Param(0)[/QUOTE]

Thanks! Guess it needed to be added as a sub-event, but that did the trick!
B
3
Posts: 7
Reputation: 289


Return to How do I....?

Who is online

Users browsing this forum: 99Instances2Go and 23 guests