EDIT: here's a fixed version, my mistake!
PHP Code:
function onTimeout() {
temp.delta={playerx-x,playery-y,(temp.delta[0]^2+temp.delta[1]^2)^.5}; // get the delta's and distance
temp.onwall=i=0; // reset i and onwall check
while (i<temp.delta[0]) { // while i is less than the distance between player and NPC
temp.onwall=onwall(x+(temp.delta[0]/temp.delta[2])*i,y+(temp.delta[1]/temp.delta[2])*i);
if (temp.onwall==1) break;
i++;
}
setTimer(0.05);
}
Key mistakes I fixed were resetting i before the loop, or else it'd grow beyond the actual distance! And also fixed the wall check, I was multiplaying i*dx/dy, and that 'cause it to check way farther than needed. You needed to divide the dx/dy by the distance, then multiply by i. This one however doesn't have a check for accuracy, though that would be easy enough to figure out(i+=accuracy

)