How do I save a HIGHSCORE

// Variables

int STOP = 1;
float count = 0;
PImage B1;
PImage Background;
PImage B2;
PImage B3;
PImage Start;
float x = 0;
float x2 = 0;
float y = 1080;
float y2 = 1080;
int Score = 0;
int Highscore;
float speed = 3;
float speed2 = 5;
// 70 tall 
// 60 Wide
void setup () {
 
  //screen size
  //size(1920, 1080);
  B1 = loadImage("B1.png");
  B2 = loadImage("B2.png");
  Background = loadImage("Background.png");
  Start = loadImage("Start.png");
  fullScreen();
}


void draw() {

  if (mousePressed) {
    STOP = 0;
  }
  image(Start, 0, 0);
  if (STOP == 0 ) {

    // Background
    background(0, 255, 0);
    image(Background, 0, 0);
    // Score
    textSize(32);
    text("Score: " + Score, 100, 100); 
    text("Highscore: " + Highscore, 100, 200);
    if (Score > Highscore) {
      Highscore = Score;
    }
    //Speed
    if (count >= 20) {
      speed = speed + 3;
      speed2 = speed2 + 3;
      count = 0;
    }
    // X pos Randomiser
    if (y == 1080) {
      x = random(50, 1850);
    }
    // x2 pos randomiser
    if (y2 == 1080) {
      x2 = random(50, 1850);
    }
    //Show Balloon 
    shape();
    // Debug Stuff
    //println("MOUSE:" + mouseX);
    //println("X pos:" + x);
    //println("MOUSE Y:" + mouseY);
    //println(speed);

    count = count + .01;
  }
}


void shape() {
  // Pos for balloon 
  image(B1, x, y = y - speed);
  image(B2, x2, y2 = y2 - speed2);
  // check for if it is too high
  if (y <= 0 || y2 <= 0) {
    y = 1080;
    y2 = 1080;
    Score = 0;
  }
  // Hit detection
  if (mousePressed == true) {
    if (!(mouseX >= x && mouseX <= x + 60 && mouseY >= y && mouseY <= y + 70 )) {
      //speed = speed + .2;
      //Score = Score - 1;
    }
    //B1
    if (mouseX >= x && mouseX <= x + 60 && mouseY >= y && mouseY <= y + 70 ) {
      y = 1080;
      Score ++;
    }
    //B2
    if (mouseX >= x2 && mouseX <= x2 + 60 && mouseY >= y2 && mouseY <= y2 + 70 ) {
      y2 = 1080;
      Score = Score + 2;
      if (speed > 1.5) {
        //speed = speed - .6;
      }
    }
  }
}

// BTW this is a game were you need to pop ballons to get your score up and i really want to start saving my highscores so they dont go away when i close out of it so yea thxs for helpingPreformatted text

1 Like

Hi @Nolan, i recommend you to look first at how to save a value to a file on your hard drive. Take a look at this:
https://processing.org/reference/saveStrings_.html

When you get this working, try to load these values the next time you run the code. See this:
https://processing.org/reference/loadStrings_.html

After this, you can think in a way to not override the values everytime, something like only override the file if your latest score is higher than the one on the file you saved.

About formating your post:
Please, add more context to your post, so other can see what’s happening with your code. And always format your code with the </> option.

2 Likes

THANK YOU SO MUCH I REALLY NEEDED HELP ON THIS
:grinning: