I am making a simple bank system and I've been having trouble with creating a button that changes the screen and It would change the screen as button is pressed. I have tried using code such as screen = 1;
in the problem but it doesnt seem to work
let sumbit;
let input;
let fullScreen;
let element, sizeback;
let clear;
let check = 2;
let mainScreen;
let screen = 0;
//if(!alert('Alert For your User!')){window.location.reload();}
function begining() {
createCanvas(1000, 500);
background(100,250);
//sizeback = background(100,200,250);
sumbit = createButton('Submit');
sumbit.mousePressed(button);
sumbit.position(190, 60);
input = createInput();
input.position(20, 60);
element = createElement('h2', 'What is the password : ');
element.position(5, 10);
fullScreen = createButton('FullScreen');
fullScreen.mousePressed(full);
fullscreen.noLoop()
textAlign(CENTER);
textSize(32);
}
function draw() {
if(screen == 0) {
begining()
} else if(screen == 1) {
bankScreen()
} else if(screen == 2) {
logout()
}
}
//FullScreen button
function full() {
let fs = fullscreen();
fullscreen(!fs);
}
//Submit button
function button() {
const password = input.value();
if(password == 2021) {
element.html('Your Correct! ' + ' The answer was ' + password);
for(var i = 0; i < 200; i++) {
push();
fill(random(255), random(255), random(255));
translate(random(height), random(width));
rotate(random(2 * PI));
text(password, 20, 20);
pop();
let next = createButton('Next');
next.mousePressed(nextpage);
next.noLoop();
}
screen = 1;
} else {
if(!alert('Would you like to try again ?')){window.location.reload();}
}
input.value('');
}
function bankScreen() {
background(100,200,250);
text("Login", 10, 50);
}
function nextpage() {
screen = 1;
//Problem!!
}
html, body {
margin: 0;
padding: 0;
}
canvas {
display: block;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.3.1/p5.min.js"></script>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Sketch</title>
<link rel="stylesheet" type="text/css" href="style.css">
<script src="libraries/p5.min.js"></script>
<script src="libraries/p5.sound.min.js"></script>
</head>
<body>
<script src="sketch.js"></script>
</body>
</html>
Thank you for the help.