I created these functions:
function generatePosition(){
var locX = Math.floor(Math.random() * 12) + 5;
var locY = Math.floor(Math.random() * 10) + 3;
console.log('MOVE 0 ' + locX + ' ' + locY ); // MOVE <pacId> <x> <y>
}
function sonoArrivato(){
var locW = [locX, locY]; //position to go
var locP = [x, y]; //position my pacman
var test = 0;
if(locP != locW){
test = 0;
} else{
test = 1;
}
}
function maintainPosition(){
var saveX = locX;
var saveY = locY;
console.log('MOVE ' + saveX + ' ' + saveY );
}
And I want that my subject goes to the position created and then create a new one from random function
generatePosition();
if (sonoArrivato.test != 0){
generatePosition();
}else{
maintainPosition();
console.error(visiblePelletCount);
}
But it's generating a new position every time