saveStrings creates a new file when exported application

I’m programming a game where I want to save the final points, like a highscore. Same problem as this topic: https://discourse.processing.org/t/save-string-to-txt-file-when-the-program-is-a-standalone-application/26898?u=abatllei
The thing is, when I run the sketch with the Processing platform, it writes the actual game points at the .txt inside de “data” folder, but when I do it with the exported application, it creates a new .txt file, with the same name, at the same folder as the application (ex. if I have the application at my Desktop, when the game has to save the value, it creates a new .txt file at Desktop).
This “new” .txt file is the same as the one that is at the “data” folder, but with the new value written.
I wish you can help me, it’s my university final project and I have to have this for the next week!

Miggt want to try finding the absolute path of your sketch and passing that through a buffered writer or filewriter if you want better consistency.

Sorry, I don’t understand. How do I do this?

ok so you might not need to worry about using a bufferedread/filewriter. Try this code and let me know if it works. This just gives you the absolutepath of the data folder.

String l;

void setup() {
  l = dataPath("test.txt");
  println(l);
  String[] data = {"test","test"};
  saveStrings(l,data);
};

void draw() {
};

public String dataPath(String where) {
  return dataFile(where).getAbsolutePath();
};

That worked! Thanks!!

1 Like