Something's logically wrong with this but what?!

Considering this:

if(this.dir==1||this.dir==5){ for(this.i=this.pseudoboat.location[0]-1;this.i>=this.pseudoboat.location[0]-3;this.i--){ for(this.c=this.pseudoboat.location[1]+1;this.c<=this.pseudoboat.location[1]+3;this.c++){ for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){ if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b*2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b*2+1))&&(this.d==2||this.d==4||this.d==6)){ this.gotleft[0] = this.i;//1=1 this.gotleft[1] = this.c;//4 instead of 6 message #v(this.gotleft[0]),#v(this.gotleft[1]); break; } } if(this.gotleft[0]!=0)break; this.d++; } if(this.gotleft[0]!=0)break; } this.d = 0; for(this.i=this.pseudoboat.location[0]+1;this.i<=this.pseudoboat.location[0]+3;this.i++){ for(this.c=this.pseudoboat.location[1]-1;this.c>=this.pseudoboat.location[1]-3;this.c--){ for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){ if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b*2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b*2+1))&&(this.d==2||this.d==4||this.d==6)){ this.gotright[0] = this.i+.5; this.gotright[1] = this.c+.5; break; } } if(this.gotright[0]!=0)break; this.d++; } if(this.gotright[0]!=0)break; } if(this.gotright[0]==0&&this.gotright[1]==0)this.gotright={this.pseudoboat.location[0]+3.5,this.pseudoboat.location[1]-3}; if(this.gotleft[0]==0&&this.gotleft[1]==0)this.gotleft={this.pseudoboat.location[0]-3,this.pseudoboat.location[1]+3.5}; }

Part of:

[CODE]if(playerenters){
setshape 1,48,48;
setfocus 30,31;
drawoverplayer;
playerx = 0;
playery = 0;
setimgpart boatspritesheet.png,0,0,48,53;
setarray this.key,10;
this.menu.redraw=0;
this.boatimage.moving = 0;
this.cannon.shooting = 0;
this.pseudoboat.location = {5,4};
this.pseudoboat.origin = {5,4};
this.level.origin = {15,19};
this.speed = .5;
redraw();
this.timeout.time = .2;
timeout = .05;
}

if(collision){
collide();
hide;
}

if(timeout){
this.timeout.time = .2;
getKeys();
if(this.menu.redraw==0){
keysmakememove();
}
else if(this.menu.redraw==1){
keysmakeachoice();
}
if(this.boatimage.moving==1){
this.timeout.time = .05;
moveBoatImage();
}
if(this.cannon.shooting==1){
this.timeout.time = .05;
movecannonballimages();
}
hideplayer this.timeout.time;
freezeplayer this.timeout.time;
timeout = this.timeout.time;
}

function getKeys(){
for (this.keyCheck = 0;this.keyCheck < 10; this.keyCheck++){
if (keydown(this.keyCheck))
this.key[this.keyCheck] = (this.key[this.keyCheck] == 0)?1:2;//1 = pressed,2 = held
else
this.key[this.keyCheck] = (this.key[this.keyCheck]>0)?-1:0;//-1 = released, 0 = not held
}
}

function redraw(){
unset client.colliders;
x=this.level.origin[0]+this.pseudoboat.origin[0]*3;
y=this.level.origin[1]+this.pseudoboat.origin[1]*3;
this.pseudoboat.location[0] = this.pseudoboat.origin[0];
this.pseudoboat.location[1] = this.pseudoboat.origin[1];
replacestring client.pseudoboat.location,0,#v(this.pseudoboat.location[0]);
replacestring client.pseudoboat.location,1,#v(this.pseudoboat.location[1]);
for(this.i=0;this.i<npcscount;this.i++){
callnpc this.i,startagainplz;
}
show;
this.menu.redraw = 0;
}

function keysmakeachoice(){
if(this.key[5]==1){
redraw();
}
}

function movecannonballimages(){
this.dx = this.gotright[0]-this.cannonball1.origin[0];
this.dy = this.gotright[1]-this.cannonball1.origin[1];

this.dist = (this.dx^2+this.dy^2)^.5;

if(this.dist>1){
this.cannonball1.origin[0] += (this.dx/this.dist)*this.speed;
this.cannonball1.origin[1] += (this.dy/this.dist)*this.speed;
showimg 20,cannonball.png,this.cannonball1.origin[0],this.cannonball1.origin[1];
changeimgvis 20,3;
}
this.dx = this.gotleft[0]-this.cannonball2.origin[0];
this.dy = this.gotleft[1]-this.cannonball2.origin[1];

this.dist = (this.dx^2+this.dy^2)^.5;

if(this.dist>1){
this.cannonball2.origin[0] += (this.dx/this.dist)*this.speed;
this.cannonball2.origin[1] += (this.dy/this.dist)*this.speed;
showimg 21,cannonball.png,this.cannonball2.origin[0],this.cannonball2.origin[1];
changeimgvis 21,3;
}
}

function keysmakememove(){
if(this.key[0]==1&&this.key[1]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[0]==0&&!this.pseudoboat.location[1]==0){
this.dir = 1;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[1]==1&&this.key[2]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[0]==0&&!this.pseudoboat.location[1]==8){
this.dir = 3;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[2]==1&&this.key[3]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[0]==10&&!this.pseudoboat.location[1]==8){
this.dir = 5;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[3]==1&&this.key[0]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[0]==10&&!this.pseudoboat.location[1]==0){
this.dir = 7;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[0]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[1]==0){
this.dir = 0;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[1]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[0]==0){
this.dir = 2;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[2]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[1]==8){
this.dir = 4;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[3]==1&&this.boatimage.moving==0&&
!this.pseudoboat.location[0]==10){
this.dir = 6;
movePseudoBoat();
showDir();
playPirateTurn();
this.boatimage.moving = 1;
}
else if(this.key[5]==1&&this.boatimage.moving==0){
shootcannon();
this.cannon.shooting = 1;
}
}

function shootcannon(){
this.d=0;
this.gotleft = {0,0};
this.gotright = {0,0};
if(this.dir==0||this.dir==4){
//check if there is a pirate boat 3 squares away and less on each side and if yes shoot it down. If no show anim but shoot nothing down.
for(this.i=this.pseudoboat.location[0];this.i>=this.pseudoboat.location[0]-3;this.i-=1){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2))&&strtofloat(#I(client.pseudoboat.location,1))==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))){
this.gotleft[0] = this.i;
this.gotleft[1] = strtofloat(#I(client.pseudoboat.location,1));
break;
}
}
if(this.gotleft[0]!=0)break;
}
for(this.i=this.pseudoboat.location[0];this.i<=this.pseudoboat.location[0]+3;this.i++){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2))&&strtofloat(#I(client.pseudoboat.location,1))==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))){
this.gotright[0] = this.i+.5;
this.gotright[1] = strtofloat(#I(client.pseudoboat.location,1));
break;
}
}
if(this.gotright[0]!=0)break;
}
if(this.gotright[0]==0&&this.gotright[1]==0)this.gotright={this.pseudoboat.location[0]+3.5,this.pseudoboat.location[1]};
if(this.gotleft[0]==0&&this.gotleft[1]==0)this.gotleft={this.pseudoboat.location[0]-3,this.pseudoboat.location[1]};
}
if(this.dir==3||this.dir==7){
for(this.i=this.pseudoboat.location[0]-1;this.i>=this.pseudoboat.location[0]-3;this.i-=1){
for(this.c=this.pseudoboat.location[1]-1;this.c>=this.pseudoboat.location[1]-3;this.c-=1){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))&&this.d%4==0){
this.gotleft[0] = this.i+1;
this.gotleft[1] = this.c+1;
break;
}
}
if(this.gotleft[0]!=0)break;
this.d++;
}
if(this.gotleft[0]!=0)break;
}
this.d = 0;
for(this.i=this.pseudoboat.location[0]+1;this.i<=this.pseudoboat.location[0]+3;this.i++){
for(this.c=this.pseudoboat.location[1]+1;this.c<=this.pseudoboat.location[1]+3;this.c++){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))&&this.d%4==0){
this.gotright[0] = this.i+.5;
this.gotright[1] = this.c+.5;
break;
}
}
if(this.gotright[0]!=0)break;
this.d++;
}
if(this.gotright[0]!=0)break;
}
if(this.gotright[0]==0&&this.gotright[1]==0)this.gotright={this.pseudoboat.location[0]+4,this.pseudoboat.location[1]+3};
if(this.gotleft[0]==0&&this.gotleft[1]==0)this.gotleft={this.pseudoboat.location[0]-3,this.pseudoboat.location[1]-3};
}
if(this.dir==2||this.dir==6){
for(this.i=this.pseudoboat.location[1];this.i>=this.pseudoboat.location[1]-3;this.i-=1){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))&&strtofloat(#I(client.pseudoboat.location,1))==strtofloat(#I(client.pseudopirateboat.location,this.b2))){
this.gotleft[0] = strtofloat(#I(client.pseudoboat.location,0))+.5;
this.gotleft[1] = this.i;
break;
}
}
if(this.gotleft[0]!=0)break;
}
for(this.i=this.pseudoboat.location[1];this.i<=this.pseudoboat.location[1]+3;this.i++){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))&&strtofloat(#I(client.pseudoboat.location,1))==strtofloat(#I(client.pseudopirateboat.location,this.b2))){
this.gotright[0] = strtofloat(#I(client.pseudoboat.location,0))+.5;
this.gotright[1] = this.i+.5;
break;
}
}
if(this.gotright[0]!=0)break;
}
if(this.gotright[0]==0&&this.gotright[1]==0)this.gotright={this.pseudoboat.location[0]+.5,this.pseudoboat.location[1]+4};
if(this.gotleft[0]==0&&this.gotleft[1]==0)this.gotleft={this.pseudoboat.location[0]+.5,this.pseudoboat.location[1]-3};
}
if(this.dir==1||this.dir==5){
for(this.i=this.pseudoboat.location[0]-1;this.i>=this.pseudoboat.location[0]-3;this.i–){
for(this.c=this.pseudoboat.location[1]+1;this.c<=this.pseudoboat.location[1]+3;this.c++){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))&&(this.d==2||this.d==4||this.d==6)){
this.gotleft[0] = this.i;//1=1
this.gotleft[1] = this.c;//4 au lieu de 6
message #v(this.gotleft[0]),#v(this.gotleft[1]);
break;
}
}
if(this.gotleft[0]!=0)break;
this.d++;
}
if(this.gotleft[0]!=0)break;
}
this.d = 0;
for(this.i=this.pseudoboat.location[0]+1;this.i<=this.pseudoboat.location[0]+3;this.i++){
for(this.c=this.pseudoboat.location[1]-1;this.c>=this.pseudoboat.location[1]-3;this.c–){
for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){
if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b2+1))&&(this.d==2||this.d==4||this.d==6)){
this.gotright[0] = this.i+.5;
this.gotright[1] = this.c+.5;
break;
}
}
if(this.gotright[0]!=0)break;
this.d++;
}
if(this.gotright[0]!=0)break;
}
if(this.gotright[0]==0&&this.gotright[1]==0)this.gotright={this.pseudoboat.location[0]+3.5,this.pseudoboat.location[1]-3};
if(this.gotleft[0]==0&&this.gotleft[1]==0)this.gotleft={this.pseudoboat.location[0]-3,this.pseudoboat.location[1]+3.5};
}
this.gotleft[0] = this.gotleft[0]*3+this.level.origin[0];
this.gotleft[1] = this.gotleft[1]*3+this.level.origin[1];
this.gotright[0] = this.gotright[0]*3+this.level.origin[0];
this.gotright[1] = this.gotright[1]*3+this.level.origin[1];
this.cannonball1.origin={x+1.5,y+1.5};
this.cannonball2.origin={x+1.5,y+1.5};
}

function showDir(){
setimgpart boatspritesheet.png,48*this.dir,0,48,53;
}

function movePseudoBoat(){
if(this.dir==0){
this.pseudoboat.location[1] = this.pseudoboat.location[1]-1;
}
if(this.dir==1){
this.pseudoboat.location[0] = this.pseudoboat.location[0]-1;
this.pseudoboat.location[1] = this.pseudoboat.location[1]-1;
}
if(this.dir==2){
this.pseudoboat.location[0] = this.pseudoboat.location[0]-1;
}
if(this.dir==3){
this.pseudoboat.location[0] = this.pseudoboat.location[0]-1;
this.pseudoboat.location[1] = this.pseudoboat.location[1]+1;

}
if(this.dir==4){
this.pseudoboat.location[1] = this.pseudoboat.location[1]+1;
}
if(this.dir==5){
this.pseudoboat.location[0] = this.pseudoboat.location[0]+1;
this.pseudoboat.location[1] = this.pseudoboat.location[1]+1;
}
if(this.dir==6){
this.pseudoboat.location[0] = this.pseudoboat.location[0]+1;
}
if(this.dir==7){
this.pseudoboat.location[0] = this.pseudoboat.location[0]+1;
this.pseudoboat.location[1] = this.pseudoboat.location[1]-1;
}

}

function moveBoatImage(){
replacestring client.pseudoboat.location,0,#v(this.pseudoboat.location[0]);
replacestring client.pseudoboat.location,1,#v(this.pseudoboat.location[1]);
this.destination = {this.level.origin[0]+(this.pseudoboat.location[0]*3),this.level.origin[1]+(this.pseudoboat.location[1]*3)}
this.dx = this.destination[0]-x;
this.dy = this.destination[1]-y;

this.dist = (this.dx^2+this.dy^2)^.5;

if(this.dist>.25){
x += (this.dx/this.dist)*this.speed;
y += (this.dy/this.dist)*this.speed;
}
else this.boatimage.moving = 0;
}

function playPirateTurn(){
for(this.i=0;this.i<=npcscount;this.i++){
callnpc this.i,playturn;
}
}

function collide(){
putnpc skullhead.png,skullhead.txt,this.level.origin[0]+this.pseudoboat.location[0]*3,this.level.origin[1]+this.pseudoboat.location[1]*3;
addstring client.colliders,#v(this.pseudoboat.location[0]);
addstring client.colliders,#v(this.pseudoboat.location[1]);
say2 You sank!#b#b#bPress S when you’re ready#bto start again.;
this.menu.redraw = 1;
}[/CODE]

It should check diagonally if a pirate boat is present but what happens on the left part is kinda random, plus it doesn’t work at all on the right part.
I’ve spent the day staring at the code and can’t figure out what’s wrong with it, here’s a picture of what it should do, the red xs being the places where it should check if there’s a pirate boat.

The only thing I can find that’s questionable is you might be exceeding the loop limit with this code:

    for(this.i=this.pseudoboat.location[0]-1;this.i>=this.pseudoboat.location[0]-3;this.i--){ 
      for(this.c=this.pseudoboat.location[1]+1;this.c<=this.pseudoboat.location[1]+3;this.c++){ 
        for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){ 
          if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b*2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b*2+1))&&(this.d==2||this.d==4||this.d==6)){ 
            this.gotleft[0] = this.i;//1=1 
            this.gotleft[1] = this.c;//4 instead of 6 
            message #v(this.gotleft[0]),#v(this.gotleft[1]); 
            break; 
          } 
        } 
        if(this.gotleft[0]!=0)break; 
        this.d++; 
      } 
      if(this.gotleft[0]!=0)break; 
    } 
    this.d = 0; 
    for(this.i=this.pseudoboat.location[0]+1;this.i<=this.pseudoboat.location[0]+3;this.i++){ 
      for(this.c=this.pseudoboat.location[1]-1;this.c>=this.pseudoboat.location[1]-3;this.c--){ 
        for(this.b=0;this.b<sarraylen(client.pseudopirateboat.location)/2;this.b++;){ 
          if(this.i==strtofloat(#I(client.pseudopirateboat.location,this.b*2))&&this.c==strtofloat(#I(client.pseudopirateboat.location,this.b*2+1))&&(this.d==2||this.d==4||this.d==6)){ 
            this.gotright[0] = this.i+.5; 
            this.gotright[1] = this.c+.5; 
            break; 
          } 
        } 
        if(this.gotright[0]!=0)break; 
        this.d++; 
      } 
      if(this.gotright[0]!=0)break; 
    } 

I can’t really follow your logic as it’s a monster in my eyes. Insert a sleep inside your for loops and see if that solves it.
I think the maximum amount of loops per frame was 1000(0) or something…

That is some unholy, unreadable code.

your for loop algorithms will be very slow. loop inside a loop inside a loop.

lol, BURN IT WITH FIRE!

but really… that’s like 36 loops and I dare everyone here to make a simpler copy of this game.

EDIT:
Btw I figured it out in midsleep, I was checking this.d wrongly, since I misinterpreted the direction in which my for loops were checking the squares.