Page 1 of 1

How to get clone index?

PostPosted: Sun Jul 01, 2012 8:23 pm
by lverona
I have several clones of an item. In my game the goal is to collect these items. I want the player to be able to save his progress, but then I need to save which items he had collected already and on next start up remove those clones from the level. How can I achieve that?

I am not sure how to get the index of the clone when I collide with it. If I could do that, then I would save the index into an array and next start up just get the indexes the player has collected and remove clones with those indexes from the level. Maybe there is a better approach?

Re: How to get clone index?

PostPosted: Sun Jul 01, 2012 9:16 pm
by skydereign
lverona wrote:I am not sure how to get the index of the clone when I collide with it. If I could do that, then I would save the index into an array and next start up just get the indexes the player has collected and remove clones with those indexes from the level. Maybe there is a better approach?

You can access any of the actor variables from the actor being collided by using collide.
player -> Collision with enemy -> Script Editor
Code: Select all
collide.r=0;

You can use the same method to get cloneindex. And, that method is usually what people use to destroy collected items.

Re: How to get clone index?

PostPosted: Mon Jul 02, 2012 5:22 pm
by lverona
Thank you.

A follow-up question - if I have a variable with a cloneindex, can I somehow use it like this:

DestroyActor("item.items[i]");

This does not seem to work - gE interprets it as a string, not as a number. So, as far as I understand, it literally searches for a clone called "items[1]".

Re: How to get clone index?

PostPosted: Mon Jul 02, 2012 5:34 pm
by skydereign
Actors have three identifying values, cloneindex, name, and clonename. cloneindex is a unique number for clones, the actor name specifies which actor it is, and clonename is the combination of the two. clonename is just a string combining name and cloneindex using name.cloneindex.
Code: Select all
DestroyActor("enemy.1"); // this destroys enemy.1

Almost all gE function use clonename to specify what actor to target (as it is the most specific identification). So from what you want to do, you have to create a string using the clonename format.
Code: Select all
char buffer[30];
sprintf(buffer, "item.%d", items[i]);
DestroyActor(buffer);

Re: How to get clone index?

PostPosted: Tue Jul 03, 2012 6:25 am
by lverona
Thank you, that's what I needed!