Hi I am new to JS p5 and I'm trying to have my code start off with a queue button. Once this button is pressed the text "Searching..." will appear followed by a cancel button. I want it so that if the user clicks the cancel button or waits a certain amount of time, the code will reset to a blank slate with just the queue button again. here is my code below:
var queueButton;
var cancelButton = null;
var queuing = false;
function setup() {
createCanvas(400, 400);
queue();
}
function draw() {
background(255, 255, 255);
if(queuing == true){
fill(0, 0, 0);
textSize(40);
}
else{
fill(255, 255, 0); //CHANGE TO WHITE
}
text("Searching...", 140, 115);
}
function queue(){
queueButton = createButton("Queue");
queueButton.mousePressed(cancel);
}
function cancel(){
queuing = !queuing;
if(cancelButton == null){
cancelButton = createButton("Cancel");
}
setTimeout(resetQueue, 120000);
cancelButton.mousePressed(resetQueue);
}
function resetQueue(){
queueing = !queuing;
if(cancelButton != null){
cancelButton.remove();
cancelButton = null;
}
}
As of right now, I can't seem to reset my code to where it's just a blank white canvas and the queue button when the time runs out or if the user clicks cancel. The code I have now changes the color if I reclick the queue button but ideally my code would reset the canvas to its original state rather than me having the code color the "Searching..." text to white. As of now I am using the p5 web editor. Any help is appreciated!