Page 1 of 1

Destroy Individual Clones?

PostPosted: Mon Jul 09, 2012 2:02 pm
by Lacotemale
Hey I am having trouble figuring out this... I just want to destroy individual clones indead of making loads of actors and doing redundant work on my game.

I have the following which works for the first item:

Code: Select all
DestroyActor("glass.clonename");
clonename+1;


I thought just incrementing the clonename would work but its not for whatever reason. :oops:

+1 for the person that helps me out! :)

Re: Destroy Individual Clones?

PostPosted: Mon Jul 09, 2012 5:35 pm
by tzoli
The destroy actor part(i think) is incorrect(I don't know theese clone things).
And the correct version of incrementing is:
Code: Select all
clonename+=1;

And it's better with a different variable:
Code: Select all
//First line:
int i=clonename;
//blabla
i+=1;

Re: Destroy Individual Clones?

PostPosted: Mon Jul 09, 2012 6:03 pm
by skydereign
clonename is a string (char pointer). Increasing a pointer just increases the point at which it points. For example a string "hello" will become "ello" if you increase it by 1. Now one thing you are doing wrong is "anything within the quotes is taken as a literal string". That is to say "glass.clonename" isn't glass's clonename. It is literally the string "glass.clonename" which can't be an actor. To do what you want to do, you have to create real clonenames.
Code: Select all
int i;
char buffer[30];
int i = 5;
sprintf(buffer, "glass.%d", i); // this makes the string hold glass.5
DestroyActor(buffer);

i++;
sprintf(buffer, "glass.%d", i); // glass.6
DestroyActor(buffer);

Re: Destroy Individual Clones?

PostPosted: Mon Jul 09, 2012 7:15 pm
by Lacotemale
OMG Skydereign, you are the best! :)

+1 for you! <3 :D

Re: Destroy Individual Clones?

PostPosted: Mon Jul 09, 2012 7:21 pm
by lcl
And of course if you use a collision event for destroying actor you can just write:
Code: Select all
DestroyActor("Collide Actor");

This destroys the actor which event actor collides with. :)

Re: Destroy Individual Clones?

PostPosted: Mon Jul 09, 2012 8:45 pm
by Hblade
Simple
Code: Select all
void DestroyClone(char *actorName, int CloneIndex)
{
    char *tmp;
    sprintf(tmp, "%s.%d", actorName, CloneIndex);
    DestroyActor(tmp);
}


Untested but should work

Example:
Code: Select all
DestroyClone("enemy", 5);


its similar to skys method but put into a void, his method is probably more effecient on memory though