i am trying to figure out how i can enable a user to step through an algorithm using a button click on P5 and JS. The other code i have takes some text and displays some custom character cells that are used in the algorithm i mentioned below. I want the user to click a next button and have it step through and wait for user input before doing each step.
Below is a code snippet
async function straightforward(patternCells, textCells){
const timeout = async ms => new Promise(res => setTimeout(res, ms));
let nextStep = false;
forwardButton = createButton("->",0,0);
forwardButton.position(confirmButton.x + backButton.width, 400);
forwardButton.mousePressed(() => next = true)
//Do some set up and display the button
for (var i = 0; i < textLen; i++) {
var j = 0;
await waitButtonNext();
//algorithm runs here
}
async function waitButtonNext() {
while (nextStep === false) await timeout(1); // pause script but avoid browser to freeze ;)
nextStep = false; // reset var
}
There are no errors in the console on chrome either.