script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Mon Oct 11, 2010 4:16 pm
by savvy
i need this script to work, because it controls who the cpus lock on to, and their animations, movement etc.
the problem is that it does NOTHING.
- Code: Select all
//slow down
if(xvelocity>0&&xvelocity>0.01)xvelocity-=0.05;
if(xvelocity<0&&xvelocity<-0.01)xvelocity+=0.05;
//setup names etc
d_1=distance(x, y, cpu1.x, cpu1.y);
d_2=distance(x, y, cpu2.x, cpu2.y);
d_3=distance(x, y, cpu3.x, cpu3.y);
d_4=distance(x, y, cpu4.x, cpu4.y);
d_p=distance(x, y, player.x, player.y);
//gravity
yvelocity+=0.1;
//movement towards cpu1
if(d_1<d_2&&d_1<d_3&&d_1<d_4&&d_1<d_p&&definecpu!=1)
{
if(x<cpu1.x+50)xvelocity-=0.1;
if(x>cpu1.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu1.x+50&&x>cpu1.x-50&&y>cpu1.y-50&&y<cpu1.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu1.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu1.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu1.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu1.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
Re: script not working
Posted:
Mon Oct 11, 2010 4:17 pm
by savvy
dang, it cut it off
oh wait, nvm. the script is like that, but the bit from below gravity down is repeated for each actor. (cpu1, cpu2, cpu3, cpu4 and player)
Re: script not working
Posted:
Mon Oct 11, 2010 4:22 pm
by savvy
maybe this...
//slow down
if(xvelocity>0&&xvelocity>0.01)xvelocity-=0.05;
if(xvelocity<0&&xvelocity<-0.01)xvelocity+=0.05;
//setup names etc
d_1=distance(x, y, cpu1.x, cpu1.y);
d_2=distance(x, y, cpu2.x, cpu2.y);
d_3=distance(x, y, cpu3.x, cpu3.y);
d_4=distance(x, y, cpu4.x, cpu4.y);
d_p=distance(x, y, player.x, player.y);
//gravity
yvelocity+=0.1;
//movement towards cpu1
if(d_1<d_2&&d_1<d_3&&d_1<d_4&&d_1<d_p&&definecpu!=1)
{
if(x<cpu1.x+50)xvelocity-=0.1;
if(x>cpu1.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu1.x+50&&x>cpu1.x-50&&y>cpu1.y-50&&y<cpu1.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu1.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu1.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu1.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu1.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards cpu2
if(d_2<d_1&&d_2<d_3&&d_2<d_4&&d_2<d_p&&definecpu!=2)
{
if(x<cpu2.x+50)xvelocity-=0.1;
if(x>cpu2.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu2.x+50&&x>cpu2.x-50&&y>cpu2.y-50&&y<cpu2.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu2.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu2.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu2.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu2.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards cpu3
if(d_3<d_2&&d_3<d_1&&d_3<d_4&&d_3<d_p&&definecpu!=3)
{
if(x<cpu3.x+50)xvelocity-=0.1;
if(x>cpu3.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu3.x+50&&x>cpu3.x-50&&y>cpu3.y-50&&y<cpu3.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu3.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu3.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu3.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu3.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards cpu4
if(d_4<d_2&&d_4<d_3&&d_4<d_1&&d_4<d_p&&definecpu!=4)
{
if(x<cpu4.x+50)xvelocity-=0.1;
if(x>cpu4.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<cpu4.x+50&&x>cpu4.x-50&&y>cpu4.y-50&&y<cpu4.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(cpu4.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(cpu4.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(cpu4.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(cpu4.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
//movement towards player
if(d_p<d_2&&d_p<d_3&&d_p<d_4&&d_p<d_1&&definecpu!=0)
{
if(x<player.x+50)xvelocity-=0.1;
if(x>player.x-50)xvelocity+=0.1;
if(xvelocity>5)xvelocity=5;
if(xvelocity<-5)xvelocity=-5;
if(x<player.x+50&&x>player.x-50&&y>player.y-50&&y<player.y+50&&jump==1)
{
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
if(xvelocity>1)xvelocity=3;yvelocity=-4;
if(xvelocity<1&&xvelocity>-1)yvelocity=-8;
jump=0;
}
if(xvelocity>1||xvelocity<-1)
{
if(player.x<x){ChangeAnimation("Event Actor", "moveL", FORWARD);}
if(player.x>x){ChangeAnimation("Event Actor", "moveR", FORWARD);}
}
else
{
if(player.x<x){ChangeAnimation("Event Actor", "idleL", FORWARD);}
if(player.x>x){ChangeAnimation("Event Actor", "idleR", FORWARD);}
}
}
Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Mon Oct 11, 2010 7:47 pm
by TSO
I'm not 100% sure on syntax. but...
But these might be things that factor in...
Not sure if the code is c# or c/c++ style.
c/c++ a bunch of if statements aren't closed open and closed anywhere...
c# one thing I might see some code doing is...
- Code: Select all
if(x<cpu1.x+50)xvelocity-=0.1;
Might just add 50 to cpu1.x '
then set xvelocity-=0.1 for current actor.
Might wanna check if code is under draw actor? or repeat? maybe isn't executing more then once so nothing happens?
those would probably be my best guesses for cause for your problem =P
Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Tue Oct 12, 2010 7:05 am
by savvy
that syntax is fine, i think the problem lays with the distance codes, seeing as this is the 1st time ive used them.
Also, in GE, if the code is on the same line as the if then it works either way, the {} are for compressing multiple lines.
the code is on an actor called "cpumaster" and each cpu inherits his events, this code is on draw actor. i found that the jump works, but the rest doesnt.
Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Tue Oct 12, 2010 11:11 am
by lcl
I am not sure about that but you maybe can't get distances of clones that way. You maybe have to use getclone();
Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Tue Oct 12, 2010 3:51 pm
by savvy
who says their clones, the cpu1 and cpu2 etc are all separate actor, they inherit from a master CPU which isn't active, but has the events on.
Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Tue Oct 12, 2010 4:20 pm
by lcl
Sorry, I didn't look carefully enough to the script.
Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Thu Oct 14, 2010 7:01 am
by savvy
no, its my use of distance thats wrong, i tested it with something else. i think its that anyway
Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT
Posted:
Thu Oct 14, 2010 7:18 am
by skydereign
Please do not make posts pointing to other posts. If you need help you can pm people, or bump this topic with more relevant information. Your first post doesn't tell me much about what I should do, and the comments are just general information. Have you gone through any testing of this? You say the problem is that it does nothing, but since the code is so strewn with if statements and similar it is hard to read through, not to mention the syntax and general coding style you use. One thing to note, you can only use one line of code after an if statement to make it exclusive. In your code you have some lines that do this.
- Code: Select all
if(xvelocity<-1)xvelocity=-3;yvelocity=-4;
That code acts just like this.
- Code: Select all
if(xvelocity<-1)
{
xvelocity=-3;
}
yvelocity=-4;
I'd love to help out, but you need to be more descriptive, and preferably clean the code up a bit. It doesn't hurt if you add {} to your if statements.