The only thing that comes to my mind:
coords_x & coords_y is not initialized.
So at gamestart they can theoretically hold any number.
Maybe try this:
var coords_x = 0;
var coords_y = 0;


no science involved