Change a particular clone parameter
Posted: Mon Apr 20, 2015 11:25 am
When the game starts, I have 30 clones created. Is there a way later on in the game to, say, change yvelocity of a particular clone, say, clone number 26?
Game Editor discussion board
http://game-editor.com/forum/
Hi, lverona!lverona wrote:When the game starts, I have 30 clones created. Is there a way later on in the game to, say, change yvelocity of a particular clone, say, clone number 26?
#define MAX 5 // number of clones
#define NAME 31 // clone's name length
char cloneName[NAME]; // clone's name
Actor *clonePlayer; // pointer to a clone
acc = -MAX; // initialize
sprintf(choose.text, "choose clone: %i", index);
int i;
// delete all previos clones
for (i = acc; i < acc + MAX; i++) {
sprintf(cloneName, "player.%d", i);
DestroyActor(cloneName);
}
// first i goes from 0 to 4, next time i goes from 5 to 9, and so on,
// because when you destroy previous clones and create new, those new clones have their indexes
// new clones will have new indexes
acc += MAX;
index = acc;
// create new clones
for (i = 0; i < MAX; i++)
CreateActor("player", "square", "no parent", "no path", (i * 100 - 200), 0, true);
// create text and border, but only when game is started
if (acc == 0) {
CreateActor("choose", "no animation", "no parent", "no path", -280, 200, true);
CreateActor("border", "no animation", "no parent", "no path", -300, -220, true);
}
index = (index - 1 < acc) ? acc + 4 : index - 1;
index = acc + fmod (index + 1, MAX);
sprintf(cloneName, "player.%d", index);
clonePlayer = getclone(cloneName);
(*clonePlayer).y -= 5;
sprintf(cloneName, "player.%d", index);
clonePlayer = getclone(cloneName);
(*clonePlayer).y += 5;
erase(0, 0, 0, 1);
setpen(255, 255, 255, 0, 1);
lineto(width - 2, 0);
lineto(width - 2, height - 2);
lineto(0, height - 2);
lineto(0, 0);
koala wrote:tl;dr
if(cloneindex == 420)
{
//whatever you want clone #420 to do
}
lverona wrote:Guys!
Big thanks for the very detailed replies. I had to add more details, but I think part of what you suggested would still be applicable.
So I have 30 clones of an actor.
How can I change yvelocity of clone number 26 from another actor, say, an actor that awaits a button press? So this is not something I can necessarily do from within the clones.
My hunch was that you can do ThatActor.26.yvelocity=3;
But this does not work. You can do ThatActor.yvelocity=3; But it will target the lowest index actor, by default ThatActor.0
if(actor.cloneindex == 26)
{
actor.yvelocity=3;
}
getclone("ThatActor.26")->yvelocity = 3;
Maybe this topic can help you somehow. It doesn't refer to your question, but it uses clones, so it might help.lverona wrote:When the game starts, I have 30 clones created. Is there a way later on in the game to, say, change yvelocity of a particular clone, say, clone number 26?
lcl wrote:
- Code: Select all
getclone("ThatActor.26")->yvelocity = 3;
char random_item[1];
short int ch;
ch=rand(26);
sprintf(random_item, "item1.%d", ch);
getclone(random_item)->yvelocity=-3;
if (cloneindex==22) // "robot.22" is the one clone of say, 100, that I need to change color or do something.
{
b=-55;
g=235; //both make yellow
}
char name[31];
sprintf(name, "clone.%d", clone_num);