1

I'm making a program where each "scene" of the story told is a void method, when one scene finishes its code (dialogue for example) then the program's "game state" changes into the next scene.

There are 8 counting the start menu + credits but the problem starts as the program goes on from the first two scenes since it starts getting larger and the dialogue is typed slower than in the first scenes.

I concluded when a scene passes onto the next scene/method the last one keeps running in the background.

Is there a way to fix this or a better way?

I tried noLoop(); before switching to the next scene but this stops the program.
I tried separating the scenes into different parts as more methods but the problem remained.

Code is confidential.

Community
  • 1
  • 1
AquaM20
  • 11
  • 2
  • 3
    What computer language are you using? Edit your question to include a [mre] created separately from your educational code that demonstrates your problem and that we can copy into our IDE, compile, run, and test. – Gilbert Le Blanc Jan 01 '23 at 11:34
  • 1
    Hi and welcome @AquaM20 . When you get a chance visit the [tour](https://stackoverflow.com/tour). It will help if you post a simplified version of your code which makes it easy to understand what works as expected and what doesn't. Overall it sounds like all states functions are executed at the same time. you could use an int value to represent the state then check which state id is current and only update that one. You can find a lengthy class based example [here](https://stackoverflow.com/questions/68042779/how-to-add-a-play-again-button/68042887#68042887) in p5.js ... – George Profenza Jan 01 '23 at 11:35
  • 1
    @GilbertLeBlanc [Processing](https://stackoverflow.com/tags/processing/info) is the language. (Think of it as a helpful java library (and minimal editor) for artists and designers to sketch/prototype with code). – George Profenza Jan 01 '23 at 11:36
  • @AquaM20 FWIW, here are a few similar processing answers: [1](https://stackoverflow.com/questions/33846379/interactive-video-player-in-processing/33892849#33892849), [2](https://stackoverflow.com/questions/32629151/processing-replacing-text/32629858#32629858), [3](https://stackoverflow.com/questions/64081842/processing-how-to-fix-timer-display-and-how-to-display-time-score-at-end-of-gam/64106780#64106780) (longer, class based example) – George Profenza Jan 01 '23 at 11:50
  • @George Profenza: Some people can tag their question with "processing" because they are processing, not using a particular Java library. – Gilbert Le Blanc Jan 01 '23 at 11:57
  • @GilbertLeBlanc Interesting. I can't recall the links, but I thoght there was something about it on Meta stackexchange about the processing tag, the processing.org tag being a synonym of processing and got used to people using specific tags (e.g. image-processing, signal-processing, natural-language-processing, etc.) recently seeing the tag used mainly for the Processing language. My bad, it could be that it still used in both cases (some sort of general processing of data and the language) ? – George Profenza Jan 01 '23 at 12:02
  • @AquaM20 without seeing the code (or a simplified version of it), hard to guess exactly. Could it be that you might be using a `for` loop over your states, updating all of them (but perhaps making only some visible in rendering), instead of updating one state at a time an switching the current state using `if/else` or `switch` ? – George Profenza Jan 01 '23 at 12:08
  • @GeorgeProfenza: Is it time for a new tag entitled 'Processing-app'? – apodidae Jan 01 '23 at 22:40
  • @apodidae It could be. Might be worth having a discussion over meta as there are multiple ways to use Processing (e.g. within the Processing editor, using processing as a java library in an arbitrary IDE (eclipse, NetBeanse, IntelliJ, etc.), the different flavours (Android Mode, Python Mode, etc.). Nice answer btw (+1) – George Profenza Jan 01 '23 at 23:56

1 Answers1

1

The following code demonstrates changing a scene using the spacebar and a switch call:

int currentScene = 0;

void setup() {
  size(400, 200);
  background(209);
  surface.setTitle("hit spacebar to change");
}

void draw() {
}

void scene1() {
  background(209);
  fill(255, 0, 0);
  circle(width/2, height/2, 50);
}

void scene2() {
  background(209);
  fill(255, 255, 0);
  circle(width/2, height/2, 100);
}

void scene3() {
  background(209);
  fill(0, 255, 255);
  circle(width/2, height/2, 150);
}

void showScene(int scene) {
  switch (scene) {
  case 1:
    scene1();
    break;
  case 2:
    scene2();
    break;
  case 3:
    scene3();
    break;
  }
}

void keyPressed() {
  if (key == 32) {
    currentScene++;
    if (currentScene > 3) {
      currentScene = 1;
    }
    showScene(currentScene);
  }
}

apodidae
  • 1,988
  • 2
  • 5
  • 9