# Trying to make something like a visual novel with a lot of booleans

**URL:** https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633
**Category:** Coding Questions
**Created:** [July 15, 2020, 10:48am UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633 "2020-07-15T10:48:57Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![qewer3322](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@qewer3322](https://discourse.processing.org/u/qewer3322)
#### Post date: [July 15, 2020, 10:48am UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/1 "2020-07-15T10:48:57Z")

</div>

I’m trying to make something like a visual novel game but without choices (but there will be other interactive stuff of course). I decided to use booleans for scenes like this:

```auto
boolean s1 = true;
boolean s2 = false;
boolean s3 = false;
boolean s4 = false;

void setup() {
  size(600, 600);
}

void draw() {
  if (s1 == true) {
    //blablabla
  }
  if (s2 == true) {
    //blablabla
  }
  if (s3 == true) {
    //blablabla
  }
  if (s4 == true) {
    //blablabla
  }
}

void mouseReleased() {
  if (s1 == true) {
    s1 = false;
    s2 = true;
  }

  if (s2 == true) {
    s2 = false;
    s3 = true;
  }

  if (s3 == true) {
    s3 = false;
    s4 = true;
  }
}

```

But the mouseReleased void doesn’t really work, it just skips to the last one. Is there another way of doing this simply? And should I use an array?

---

<div class="post-metadata">

### Author: ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)
#### Post date: [July 15, 2020, 11:07am UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/2 "2020-07-15T11:07:22Z")

</div>

Hi @qewer3322, the reason why you pass from the s1 to the s4 is because you are following the cicle of ifs; s1 == true, then S2 = true and go for the next if with s2 = true, then s3 goes to true, and you go to the last if with the s3 = true.

You can fix it doing if else statements:

```auto

  if (s1 == true) {
    s1 = false;
    s2 = true;
  }else
  if (s2 == true) {
    s2 = false;
    s3 = true;
  }else
  if (s3 == true) {
    s3 = false;
    s4 = true;
  }

```

And you can do in many ways, yes, you can use arrays, probably will be better in order to have less variables and better organization.

I tried something similar time ago, and I prefer to use an int, and a switch statement, and just change my int variable to select the phase I want to go.

Hope this helps you, Good luck 🍀

---

<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: [July 15, 2020, 1:35pm UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/3 "2020-07-15T13:35:10Z")

</div>

I agree

switch() even better

it’s possible to have a function page0Desert, page1Ocean … for each page

```auto
int page=0; 

void setup() {
  size(600, 600);
  background(0);
}

void draw() {
  background(0); 
  if (page==0) {
    //blablabla
    text(page, 111, 111);
  } else if (page==1) {
    //blablabla
    text(page, 111, 111);
  } else if (page==2) {
    //blablabla
    text(page, 111, 111);
  } else if (page==3) {
    //blablabla
    text(page, 111, 111);
  }
}

void mouseReleased() {
  page++;
}

```

---

<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: [July 15, 2020, 1:50pm UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/4 "2020-07-15T13:50:04Z")

</div>

check out

[https://www.openprocessing.org/sketch/65678#](https://www.openprocessing.org/sketch/65678#)

---

<div class="post-metadata">

### Author: ![qewer3322](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@qewer3322](https://discourse.processing.org/u/qewer3322)
#### Post date: [July 15, 2020, 2:02pm UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/5 "2020-07-15T14:02:02Z")

</div>

Hmm this is way simpler, I’ll try it thanks!

---

<div class="post-metadata">

### Author: ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)
#### Post date: [July 16, 2020, 2:44am UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/6 "2020-07-16T02:44:29Z")

</div>

A visual novel without choice sounds like you want a series of scenes in linear order.

```auto
int scene = 0;

```

You could now load a different background image for each scene.

```auto
PImage[] backgrounds;
// ...

void draw() {
   image(backgrounds[scene]);
}
void keyReleased() {
  scene++;
}

```

We could also load things that are in that scene.

```auto
ArrayList<Sprites> sprites;
//...

void draw() {
  image(backgrounds[scene]);
  for(Sprite s : sprites) {
    if(s.in(scene)==true) {
      s.render();
    }
  }
}
void keyReleased() {
  scene++;
}

```

So, in general, in addition to switching between code rules for each scene, you can also create the common elements of your scenes as data, rather than rules, have the simple rules be “show whatever is in this scene”.

---

<div class="post-metadata">

### Author: ![qewer3322](https://avatars.discourse-cdn.com/v4/letter/q/e19adc/32.png) [@qewer3322](https://discourse.processing.org/u/qewer3322)
#### Post date: [July 16, 2020, 10:04am UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/7 "2020-07-16T10:04:00Z")

</div>

This also helps, thanks!

---

<div class="post-metadata">

### Author: ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)
#### Post date: [July 16, 2020, 11:47am UTC](https://discourse.processing.org/t/trying-to-make-something-like-a-visual-novel-with-a-lot-of-booleans/22633/8 "2020-07-16T11:47:27Z")

</div>

Hello,

I often use these:

> **[keyPressed() / Reference](https://www.processing.org/reference/keyPressed_.html)**
>
> The keyPressed() function is called once every time a key is pressed. The key that was pressed is stored in the key variable. For non-ASCII keys, use the keyCode varia…

> **[case / Reference](https://processing.org/reference/case.html)**
>
> Denotes the different names to be evaluated with the parameter in the switch structure.

> **[case / Reference](https://processing.org/reference/case.html)**
>
> Denotes the different names to be evaluated with the parameter in the switch structure.

And weave a web of code to unleash my creative vision.

In this example it is transition with time (can be a keyPressed() or other) and using case statements:

> [@Animation that transitions using frameCount](https://discourse.processing.org/t/animation-that-transitions-using-framecount/15378):
>
> A very simple example that transitions through scenes over time: // Author: GLV // Date: 2019-11-10 // Description: // Animate over time using frameCount // A very simple example that: // Uses frameCount to keep track of time // Fades in and out by modifying alpha component of HSB color // Cycles through HSB colors int scene = 0; int sec = 60; float alpha = 0; void setup() { size(500, 500); textSize(36); textAlign(CENTER, CENTER); colorMode(HSB, 360, 100, 100, 100); } void draw()…

`:)`
