Thanks for all the help, i tweaked the codes slightly and it worked fine now.
This is the current code:
function update_distance_position(ai_dist){
if (ai_dist < distance){
return(1);
}
else{
return(0);
}
}
function update_position(){
if (you.check_identify == player.check_identify){
position=1;
position += update_distance_position(ai1_distance);
position += update_distance_position(ai2_distance);
position += update_distance_position(ai3_distance);
}
}
This function is inside the while loop.
Thanks again =)