How to get clone index?

Non-platform specific questions.

How to get clone index?

Postby lverona » Sun Jul 01, 2012 8:23 pm

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?
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to get clone index?

Postby skydereign » Sun Jul 01, 2012 9:16 pm

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

Re: How to get clone index?

Postby lverona » Mon Jul 02, 2012 5:22 pm

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]".
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score

Re: How to get clone index?

Postby skydereign » Mon Jul 02, 2012 5:34 pm

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

Re: How to get clone index?

Postby lverona » Tue Jul 03, 2012 6:25 am

Thank you, that's what I needed!
lverona
 
Posts: 221
Joined: Tue Apr 24, 2012 11:54 am
Score: 1 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest