Q: Why is my maze generator not detecting if a cell has been visited in p5.js? I am trying to make a maze generator, and almost everything is working so far. I have been able to set my position to a random pos,  and then I repeat the standard() function. In the function, I add pos to posList, and then I choose a random direction. Next, I check if the cell has been visited by running through all of the posList vectors in reverse. I haven't executed the code that backtracks yet. If visited = false then I move to the square and execute the yet-to-be-made path() function. However, for some reason, the mover just doesn't detect if a cell has been visited or not. I am using p5.js. What am I doing wrong?
var posList = [];
var pos;
var tempo;
var boole = false;
var direc;
var mka = 0;
function setup() {
  createCanvas(400, 400);
  //Set up position
  pos = createVector(floor(random(3)), floor(random(3)));
  frameRate(1)
}

//Choose a direction
function direct(dire) {
  if(dire === 0) {
    return(createVector(0, -1));
  } else if(dire === 1) {
    return(createVector(1, 0));
  } else if(dire === 2) {
    return(createVector(0, 1));
  } else {
    return(createVector(-1, 0));
  }
}

/foLo stands fo forLoop
function foLo() {
  //If we have checked less than three directions and know there is a possibility for moving
  if(mka < 4) {
    //tempoRARY, this is what we use to see if the cell has been visited
    tempo = createVector(pos.x + direct(direc).x, pos.y + direct(direc).y);
    //Go through posList backwards
    for(var i = posList.length - 1; i >= 0; i --) {
      //If the cell has been visited or the cell is off of the screen
      if(tempo ===  posList[i]) {
        //Change the direction
        direc ++;
        //Roll over direction value
        if(direc === 4) {
          direc = 0;
        }
        //Re-execute on next frame
        foLo();
        //The cell has been visited
        boole = false;
        //Debugging
        console.log(direc)
        mka++;
      } else if(tempo.x < 0 || tempo.x > 2 || tempo.y < 0 || tempo.y > 2) {
        direc ++;
        if(direc === 4) {
          direc = 0;
        }
        foLo();
        boole = false;
        console.log(direc)
        mka++;
      }
    }
    //If it wasn't visited (Happens every time for some reason)
    if(boole === true) {
      //position is now the temporary value
      pos = tempo;
      console.log("works")
      mka = 0;
    }
  }
}

function standard() {
  //Add pos to posList
  posList.push(pos);
  //Random direction
  direc = floor(random(4));
  //Convert to vector
  direct(direc);
  foLo();
  //Tracks pos
  fill(255, 255, 0);
  rect(pos.x*100+50, pos.y*100+50, 50, 50)
}

function draw() {
  background(255);
  fill(0);
  noStroke();
  //draw grid
  for(var i = 0; i < 4; i ++) {
    rect(i*100,0,50,350);
    rect(0, i*100, 350, 50);
  }
  standard();
  boole = true;
  console.log(pos)
  console.log(posList);
}


A: Your issue is on the line where you compare two vectors if(tempo ===  posList[i]) {: This will never be true.
You can verify that with the following code (in setup() for example):
const v1 = new p5.Vector(1, 0);
const v2 = new p5.Vector(1, 0);
const v3 = new p5.Vector(1, 1);

console.log(v1 === v2) // false
console.log(v1 === v3) // false

This is because despite having the same value v1 and v2 are referencing two different objects.
What you could do is using the p5.Vector.equals function. The doc has the following example:
let v1 = createVector(10.0, 20.0, 30.0);
let v2 = createVector(10.0, 20.0, 30.0);
let v3 = createVector(0.0, 0.0, 0.0);
print(v1.equals(v2)); // true
print(v1.equals(v3)); // false

This might not give you a working algorithm because I suspect you have other logical errors (but I could be wrong or you will debug them later on) but at least this part of the code will do what you expect.

Another solution is to use a Set instead of your list of positions. The cons of this solution is that you will have to adapt your code to handle the "out of grid" position situation. However when you want to keep track of visited items a Set is usually a great solution because the access time is constant. That this means is that to define is a position has already been visited it will always take the same time (you'll do something like visitedSet.has(positionToCheck), whereas with your solution where you iterate through a list the more cells you have visited to longer it will take to check if the cell is in the list.
The Set solution will require that you transform your vectors before adding them to the set though sine, has I explained before you cannot simply compare vectors. So you could check for their string representation with something like this:
const visitedCells = new Set();
const vectorToString = (v) => `${v.x},{$v.y}` // function to get the vector representation

// ...
visitedCells.add(vectorToString(oneCell)); // Mark the cell as visited

visited = visitedCells.has(vectorToString(anotherCell))


Also has a general advice you should pay attention to your variables and functions name. For example
// foLo stands fo forLoop
function foLo() {

is a big smell: Your function name should be descriptive, when you see your function call foLo(); having to find the comment next to the function declaration makes the code less readable. You could call it generateMaze() and this way you'll know what it's doing without having to look at the function code.
Same for
//tempoRARY, this is what we use to see if the cell has been visited
tempo = createVector(pos.x + direct(direc).x, pos.y + direct(direc).y);

You could simply rename tempo to cellToVisit for example.
Or boole: naming a boolean boole doesn't convey a lot of information.
That could look like some minor details when you just wrote the code but when your code will be several hundred lines or when you read it again after taking several days of break, you'll thank past you for taking care of that.
