script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

You must understand the Game Editor concepts, before post here.

script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby savvy » Mon Oct 11, 2010 4:16 pm

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);}
}

:(
Last edited by savvy on Mon Oct 11, 2010 4:23 pm, edited 1 time in total.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: script not working

Postby savvy » Mon Oct 11, 2010 4:17 pm

dang, it cut it off :x
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)
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: script not working

Postby savvy » Mon Oct 11, 2010 4:22 pm

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);}
}

}
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby TSO » Mon Oct 11, 2010 7:47 pm

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
TSO
 
Posts: 87
Joined: Thu Sep 02, 2010 5:53 pm
Score: 4 Give a positive score

Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby savvy » Tue Oct 12, 2010 7:05 am

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.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby lcl » Tue Oct 12, 2010 11:11 am

I am not sure about that but you maybe can't get distances of clones that way. You maybe have to use getclone(); :D
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby savvy » Tue Oct 12, 2010 3:51 pm

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.
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby lcl » Tue Oct 12, 2010 4:20 pm

Sorry, I didn't look carefully enough to the script. :P
User avatar
lcl
 
Posts: 2339
Joined: Thu Mar 25, 2010 5:55 pm
Location: Finland
Score: 276 Give a positive score

Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby savvy » Thu Oct 14, 2010 7:01 am

no, its my use of distance thats wrong, i tested it with something else. i think its that anyway
--> For my help, i ask for a simple +1 if it helps! ^-^
--> I dont code, I type art which you dont understand.
--> I keep winning the 3D model challenge at college, teacher says: "you keep winning im not giving you prizes".
User avatar
savvy
 
Posts: 494
Joined: Wed Jun 03, 2009 11:55 am
Location: England
Score: 44 Give a positive score

Re: script not working LOOK AT BOTTOM POST FOR FULL SCRIPT

Postby skydereign » Thu Oct 14, 2010 7:18 am

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


Return to Advanced Topics

Who is online

Users browsing this forum: No registered users and 1 guest

cron