Destroy Individual Clones?

Non-platform specific questions.

Destroy Individual Clones?

Postby Lacotemale » Mon Jul 09, 2012 2:02 pm

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! :)
User avatar
Lacotemale
 
Posts: 285
Joined: Wed Dec 08, 2010 7:47 pm
Location: /home
Score: 7 Give a positive score

Re: Destroy Individual Clones?

Postby tzoli » Mon Jul 09, 2012 5:35 pm

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;
Creepers are capable of climbing ladders, despite lacking arms. (Minecraft wiki)
User avatar
tzoli
 
Posts: 343
Joined: Sat Jun 12, 2010 6:54 pm
Location: Behind you
Score: 15 Give a positive score

Re: Destroy Individual Clones?

Postby skydereign » Mon Jul 09, 2012 6:03 pm

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);
User avatar
skydereign
 
Posts: 3510
Joined: Mon Jul 28, 2008 8:29 am
Score: 589 Give a positive score

Re: Destroy Individual Clones?

Postby Lacotemale » Mon Jul 09, 2012 7:15 pm

OMG Skydereign, you are the best! :)

+1 for you! <3 :D
User avatar
Lacotemale
 
Posts: 285
Joined: Wed Dec 08, 2010 7:47 pm
Location: /home
Score: 7 Give a positive score

Re: Destroy Individual Clones?

Postby lcl » Mon Jul 09, 2012 7:21 pm

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. :)
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: Destroy Individual Clones?

Postby Hblade » Mon Jul 09, 2012 8:45 pm

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
Subscribe to my YouTube? - Yes| No
User avatar
Hblade
 
Posts: 4455
Joined: Fri Dec 08, 2006 11:14 pm
Score: 181 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest

cron