Page 1 of 1

Killing all Clones

PostPosted: Thu May 24, 2012 5:52 pm
by 666applestore
Hi,

Pretty simple question here, and am having trouble finding it on forum. I'm cloning a common enemy in a sidescrolling platform game. I'm using a Collision and DestroyActor on the enemy when he is hit with a bullet. However, this obviously ends up destroying all of the clones, when I just want the bullet to kill that specific clone. Is there a code I can add to the DestroyActor or Collision that can do this? Some kind of "untether from other clones" button or script? Otherwise I would have to add a new Actor, import graphics and scripts over and over again for each of this type of enemy (which is tedious).

Thanks!
666AppleStore

Re: Killing all Clones

PostPosted: Thu May 24, 2012 6:06 pm
by phyzix5761
Hi there. First create an actor variable named killme. In the collision event of the clone add

Code: Select all
killme=1;


in the draw event of the clone add

Code: Select all
if(killme==1)
{
   //blah blah blah
   DestroyActor("Event Actor");

}


that should only destroy the clone that collided.

Re: Killing all Clones

PostPosted: Thu May 24, 2012 7:03 pm
by 666applestore
Hey, thanks for the help, I'm getting closer, but i havent really worked w variables before (and im not that great w code). I'm doing this with two clones for now (enemy.0, enemy.1) It now is killing the clone specified (enemy.0), even if I shoot the other clone. When I look in the code I can see that whatever I change in the DrawActor is changed in both clones so I must not be doing something right with the variable.

Here's what I did following your directions

1. I went to Global Code, clicked Variables, clicked Add Variable, named it killme, it's an Integer, Actor Variable, Array:No, Size: nothing, Save Group: nothing. Clicked OK.

2. Removed DestroyActor in Collision with Bullet

3. Added new Collision Event on Any Side Of Bullet: killme=1;

4.Added to DrawActor > Script Editor >
Code: Select all
if(killme==1)
{
     
     DestroyActor("enemy.0");

}


Thanks again!

Re: Killing all Clones

PostPosted: Thu May 24, 2012 7:06 pm
by 666applestore
ok I needed to just put "Event Actor" and not specify the enemy still. It seems to be working now, great thanks!

Re: Killing all Clones

PostPosted: Thu May 24, 2012 8:29 pm
by skydereign
In a collision event you can specify the event actor and the colliding actor (the other actor).
bullet -> Collision with enemy -> Script Editor
Code: Select all
DestroyActor("Collide Actor");