Page 1 of 1
clone help

Posted:
Sun Jan 09, 2011 5:49 pm
by Imperialjester
hello every one i have a problem. im trying to make my actor stop when close to a clone but i dont want to make a code for each clone i have. is there a way i can make it so that it stops when my actor gets close to any clone right now my code is
- Code: Select all
if(distance(x, y, wall.x, wall.y) >= -1){
if(dir == 1){
ChangeAnimation("Event Actor", "PlayerIdleRight", NO_CHANGE);
dir=3;}
if(dir == 2){
ChangeAnimation("Event Actor", "PlayerIdleLeft", NO_CHANGE);
dir=3;}
problem is it only stops at the original clone
Re: clone help

Posted:
Sun Jan 09, 2011 6:00 pm
by schnellboot
so what is the clone?
Re: clone help

Posted:
Sun Jan 09, 2011 6:06 pm
by Imperialjester
the wall is the clone but i have 2 i want it to be able to stop at the 2nd clone not just the first one but i dont want to have to make a new code for each clone.
Re: clone help

Posted:
Sun Jan 09, 2011 6:39 pm
by schnellboot
Well the code given is not the code for stop right?
Re: clone help

Posted:
Sun Jan 09, 2011 6:48 pm
by Imperialjester
it is, let me explian my code. when my actor's x position is reletive to -1 of wall's x position dir =3 if dir = 3 x+=0 x-=0
Re: clone help

Posted:
Sun Jan 09, 2011 7:04 pm
by schnellboot
hm.. it should work for both walls cuz you didn't use cloneindex
could I see the ged?
Re: clone help

Posted:
Sun Jan 09, 2011 7:49 pm
by Imperialjester
ok i removed my old code and changed it a little im still haveing a problem i will show you mmy whole code for that actor
this is in my enemys draw actor
- Code: Select all
if(Army1.x > x + 320){
Enemycover=0;
EnemyShoot=0;}
if(Army1.x < x - 320){
Enemycover=0;
EnemyShoot=0;}
if (EnemyShoot==1){
CreateTimer("Event Actor", "enemybullettime", 900);}
if(EnemyShoot==0){
DestroyActor("EnemyBullet");}
if(EnemyHealth<=0)
DestroyActor("Event Actor");
if(Enemycover == 1){
if(wall.x > x + 1){
x+=2.6;}
if(wall.x < x - 1){
x-=2.6;}
}
EnemyShoot=1;
Enemycover=1;
if(wall.x > x + 320){
Enemycover=0;}
if(wall.x < x - 320){
Enemycover=0;}
this is for my squad commander game and i dont ant to post the .ged until im ready to release v0.2 i am not using clone index
Re: clone help

Posted:
Sun Jan 09, 2011 9:41 pm
by skydereign
The problem is that you are using name.variable. You can't specify the clone you are accessing, in these cases wall and Army1. You'll have to get the Actor*s for the clones, and use that to check the variables. To do this though, you'll have to setup a loop checking all wall's xy coordinates. If this event is in a collision event, then you won't have this problem because you can use collide.variable instead of name.variable, which is a precise representation of the current wall.
Re: clone help

Posted:
Sun Jan 09, 2011 10:02 pm
by Imperialjester
ok, how do i do that?

Re: clone help

Posted:
Mon Jan 10, 2011 1:33 am
by skydereign
Here's one of several posts explaining getCloneIdx, a derivative of the getclone2 function. Use it to get the Actor* of the wall, to check the x coordinate.
- Code: Select all
int i;
Actor* currentWall;
for(i=0;i<ActorCount("wall");i++)
{
currentWall=getCloneIdx("wall",i);
if(wall->x > x+1)
{
//
}
else if(wall->x < x-1)
{
//
}
}
This is a short example of how you might implement it. Typing this out makes me think it isn't optimal, but without more information on what you are doing, I can't really make it that much better.
Re: clone help

Posted:
Mon Jan 10, 2011 3:35 pm
by Imperialjester
thanks for all the help but i dont have a function called getcloneidx and i have the newest version of GE
Re: clone help

Posted:
Mon Jan 10, 2011 4:55 pm
by Bee-Ant
Here's my version of code...
- Code: Select all
int i;
Actor *check;
char str[32];
for(i=0;i<ActorCount("wall");i++)
{
sprintf(str,"wall.%i",i);
check=getclone(str);
if(distance(x,y,check->x,check->y)<10)
{
//stop action here
}
}