Frogger High score

So I am trying to make a high score system for my frogger game I am using JSONObjects but its a little confusing can anyone show an example or explain it.

Thanks.

Hi @king_B99

Its quite easy … maybe you can have a look here first …
JSON Load and Save data
It ahows you how to load/save/access your data.

If you’ve tried it and post your approach here we can check if there a issues…

Cheers
— mnse

1 Like

see Reference / Processing.org

here


void setup() {

  size(700, 700); 

  JSONArray values;

  values = new JSONArray();

  String[] name = { "Ann", "Frank", "Will" };
  String[] score = { "102", "201", "23" };

  for (int i = 0; i < name.length; i++) {

    JSONObject animal = new JSONObject();

    animal.setInt("id", i);
    animal.setString("name", name[i]);
    animal.setString("score", score[i]);

    values.setJSONObject(i, animal);
  }

  saveJSONArray(values, "data/new.json");

  values = null;

  println("saved.");
}

void draw() {
  //
  background(0); 
  text("any key to load", 33, 33);
}

//------------------------------------------------------------------

void keyPressed() {

  println("load");

  JSONArray values=null;

  values = loadJSONArray(dataPath("")+"/new.json");

  for (int i = 0; i < values.size(); i++) {

    JSONObject HighScore = values.getJSONObject(i); 

    int id = HighScore.getInt("id");
    String name =HighScore.getString("name");
    String score = HighScore.getString("score");

    println(id + ", " + name + " has " + score);
  }
}

Obviously you have to apply this to your program where players have a score