My text only appears as soon as I press the button of which it’s supposed to run, but it only appears for less than a second.
my code:
int userNumber;
float MyNumber = random (1, 10);
int Guesses = 0;
void setup() {
size(500, 500);
background(0);
textSize(30);
}
void draw () {
background(0);
text ("Attempts", 250, 265);
text ("Choose a number", 40, 60);
text ("Your number: " +userNumber, 230, 200);
text (Guesses, 400, 270);
}
void keyPressed() {
userNumber = key-48;
Guesses += 1;
if (userNumber > int(MyNumber)) {
text("Wrong number. Smaller please.", 40, 400);
} else if (userNumber < int(MyNumber)) {
text("Wrong number. Bigger please.", 40, 400);
} else if (userNumber == int(MyNumber)) {
text("CORRECT!", 40, 400);
text("Left click to restart", 40, 460);
}
}
void mouseClicked(){
userNumber = 0;
Guesses = 0;
MyNumber = random (1, 10);
text ("Choose a number", 40, 60);
}