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

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:

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?

2 Likes

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:


  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 :four_leaf_clover:

4 Likes

I agree

switch() even better

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

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++;
}
2 Likes

check out

https://www.openprocessing.org/sketch/65678#

3 Likes

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

2 Likes

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

int scene  = 0;

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

PImage[] backgrounds;
// ...

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

We could also load things that are in that scene.

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”.

4 Likes

This also helps, thanks!

Hello,

I often use these:

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:

:)

2 Likes