Save multiple strings into one file
in
Programming Questions
•
1 year ago
Hey all,
andrewgies17
I am making a game, (just started, figuring out basics, dont have much code), that will eventually allow the user to save the game into a file. I am going to use saveStrings, and hide the txt file into a .plw (faux extention), so users can't easily hack the game. I will have many variables (ex. life, points, etc.) controlling the state of the game, and I would like to consolidate them into one file. Can I do something like saveStrings("SavedGame.plw", aString + anotherString); ? Thanks in advance. This is my (not working) code so far:
- String[] words = new String[5];
- String[] wordsInput = new String[5];
- int[] points = new int[2];
- void setup() {
- for(int l = 0; l < 5; l++) {
- words[l] = "Hello, My name is Andrew";
- }
- points[0] = 27;
- points[1] = 48;
- saveStrings("SavedGame.plw", words);
- saveStrings("SavedGame.plw", str(points));
- wordsInput = loadStrings("SavedGame.plw");
- println(wordsInput);
- }
What I get is a overwritten file that displays:
[0] "27"
[1] "48"
What I want is a file that reads:
[0] "Hello, My name is Andrew"
[1] "Hello, My name is Andrew"
[2] "Hello, My name is Andrew"
[3] "Hello, My name is Andrew"
[4] "Hello, My name is Andrew"
[5] "27"
[6] "48"
Thanks,
andrewgies17
1