# Is this realizable in Processing?

**URL:** https://discourse.processing.org/t/is-this-realizable-in-processing/15544
**Category:** Coding Questions
**Created:** [November 16, 2019, 4:22pm UTC](https://discourse.processing.org/t/is-this-realizable-in-processing/15544 "2019-11-16T16:22:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ImDaGr3en](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@ImDaGr3en](https://discourse.processing.org/u/ImDaGr3en)
#### Post date: [November 16, 2019, 4:22pm UTC](https://discourse.processing.org/t/is-this-realizable-in-processing/15544/1 "2019-11-16T16:22:12Z")

</div>

**Hi folks!**

I just need your help for a simple question. I’m about on doing a sort of mini-game in which you can choose between playing against the CPU or another player… but I don’t know how!

In fact, I need to have a “menu screen” to show before the actual game starts in which you can have a text like “Choose if you want to play single-player mode or two-player mode” and then you have two buttons to press, pressing one you’re gonna choose single-player mode and with the other one you’re gonna add a friend to the game; and this should be shown forever until you don’t press one of the buttons.

The problem is, if I do something like a `while();` or `do {} while();` cycle that runs until I do something, it does show nothing on the window; it just keeps showing a blank window forever (even if I try to press the buttons, guessing where the hell they should be, it doesn’t load them and I can’t interact with the program in any way).  
So, I need someone’s help to do this, I just need this to be alive!! Plz… Or at least say me if you’re sure that this is impossible or there’s a way of doing this…

_Thanks for the support and the answers!!!_

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 16, 2019, 6:18pm UTC](https://discourse.processing.org/t/is-this-realizable-in-processing/15544/2 "2019-11-16T18:18:44Z")

</div>

That is possible.

The idea is that `draw()` has different **states** it runs in.

E.g.:

- state 0 means we ask for number of players
- state 1 we are in a game human against PC
- state 2 we are in a game of two humans

Thus no `while()` needed just let draw() run again and again:

```auto
void draw() {
  if(state==0) {
    background(0);
    text ("please click the number of players", 112,112);
  }
  else if (state==1) {
    background(0);
    //game...
  }
  else if (state==2) {
    background(0);
    //game...
  }
}

```

Chrisir

---

<div class="post-metadata">

### Author: ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)
#### Post date: [November 16, 2019, 6:23pm UTC](https://discourse.processing.org/t/is-this-realizable-in-processing/15544/3 "2019-11-16T18:23:06Z")

</div>

> [@ImDaGr3en](#):
>
> if I do something like a `while();` or `do {} while();` cycle that runs until I do something, it does show nothing on the window

That’s right. The function draw() updates the screen only once at its end. Hence you don’t see anything.  
Therefore use my method / technique above where you use the fact that `draw()` in itself loops automatically. It runs 60 times per second. But it runs only the lines that belong to the current state due to the if-clause. That’s the trick.  
(Nothing outside the if-clauses is allowed. This is a rule of thumb.)

When you change the state to 1 or to 2 respectively, the next screen for the game is shown.

- A Help Screen or a High Score Screen would be other possible states.

In mousePressed() or keyPressed() you need the same `if..else if..`-clause to distinguish the inputs depending on the state:

- E.g. when you enter the number of players, that’s possible in state 0, but **not** in state 1 or 2.

Chrisir

---

<div class="post-metadata">

### Author: ![ImDaGr3en](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@ImDaGr3en](https://discourse.processing.org/u/ImDaGr3en)
#### Post date: [November 23, 2019, 3:06pm UTC](https://discourse.processing.org/t/is-this-realizable-in-processing/15544/4 "2019-11-23T15:06:41Z")

</div>

thx bro it worked perfectly!!! working a bit more to finish my project and then I’ll post it with the copyrights to your contribute!!!

---

<div class="post-metadata">

### Author: ![ImDaGr3en](https://avatars.discourse-cdn.com/v4/letter/i/f0a364/32.png) [@ImDaGr3en](https://discourse.processing.org/u/ImDaGr3en)
#### Post date: [November 23, 2019, 3:08pm UTC](https://discourse.processing.org/t/is-this-realizable-in-processing/15544/5 "2019-11-23T15:08:50Z")

</div>

ok so I know which is the problem that drives me round the bend every time I’m about to code something like that!!! thx bro!!
