# My text only appears for less than half a second

**URL:** <https://discourse.processing.org/t/my-text-only-appears-for-less-than-half-a-second/20701>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [May 10, 2020, 5:09am UTC](https://discourse.processing.org/t/my-text-only-appears-for-less-than-half-a-second/20701 "2020-05-10T05:09:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![anklesatrisk](https://avatars.discourse-cdn.com/v4/letter/a/3bc359/32.png) [@anklesatrisk](https://discourse.processing.org/u/anklesatrisk)\
**Post date:** [May 10, 2020, 5:09am UTC](https://discourse.processing.org/t/my-text-only-appears-for-less-than-half-a-second/20701/1 "2020-05-10T05:09:39Z")

</div>

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:

```auto
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);
}

```

---

<div class="post-metadata">

**Author:** ![noel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/noel/32/213_2.png) [@noel](https://discourse.processing.org/u/noel)\
**Post date:** [May 10, 2020, 6:01am UTC](https://discourse.processing.org/t/my-text-only-appears-for-less-than-half-a-second/20701/2 "2020-05-10T06:01:02Z")

</div>

Hi @anklesatrisk  
Please format your code above by clicking that pencil, and selecting your code. Then you click the format button.  
What I already can see, is that you are drawing text in the mousePressed function. You must draw in the draw() loop with an if block. When you click you set a boolean in the mousePressed function to true, that will trigger an if block in draw().
