I have found something out about saving files it works the same as loading but if the file was made before you run “Run on device” it won’t work. More details below.
loadStrings -
1: loading files made before “Run on device” - works
2: loading files made by the app - works
saveStrings -
1: saving onto files made before “Run on device” - error
2: saving onto files made by the app - works
Some code below for you to test run.
String[] SaveData = new String[1];
String[] LoadData = new String[1];
String[] FileData = {"My text is in here"};
String FileName = "File1.txt";
void setup() {
fullScreen();
SaveData[0] = "No data saved yet";
LoadData[0] = "No data loaded yet";
}
void draw() {
background(255);
//Save data section and graphics
fill(255, 0, 0);
stroke(0);
strokeWeight(2);
rect(0, 0, width, height/2);
fill(0);
textSize(25);
text("Click here to save", width/2 - textWidth("Click here to save")/2, height/4 - 25);
text(SaveData[0], width/2 - textWidth(SaveData[0])/2, height/4 + 25);
//Save if mouse is pressed below the half of the screen height
if (mousePressed && mouseY < height/2) {
//save to the name FileName or make a new txt called FileName inside of the data folder
//comment this out to save the text in the string you set above
FileData[0] = str(round(random(10)));
SaveData = FileData;
saveStrings(FileName, FileData);
background(0);
println("Saved");
}
//Load data section and graphics
fill(0, 255, 0);
stroke(0);
strokeWeight(2);
rect(0, height/2, width, height/2);
fill(0);
textSize(25);
text("Click here to load", width/2 - textWidth("Click here to load")/2, height/2 + height/4 - 25);
text(LoadData[0], width/2 - textWidth(LoadData[0])/2, height/2 + height/4 + 25);
//Load if mouse is Pressed above half of the screen height
if (mousePressed && mouseY > height/2) {
//load the file from the directory of FileName which is inside of the data folder
LoadData = loadStrings(FileName);
background(0);
println("Loaded");
}
}
First run the code and see how it works when you understand try this below.
Make a folder called data inside the sketch folder.
Then make a .txt inside of the folder “data” and name it the same as the “String FileName” that is inside of the code above. Inside of the app load the file first then try and save it.
This helps visualize what I am saying for your self.
I suggest that if you wan’t to load image say for your character to draw in your app this works. But for storing data like where the character is and how much money he’s made, you have to make the file from inside the app like show in the example above. Hope this helps @imaginativeCODE
If you have any Problems understanding what I just said then let me know so it will help others understand better in the future too.