We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Im trying to save the games highscore.
void loadHighscore(){
// Load text file as a string
String[] scoreboard = loadStrings("Highscore.txt");
// Convert string into an array of integers using ',' as a delimiter
Highscore = int(scoreboard[0]);
}
void saveHighscore(){
String[] scoreboard = new String[2];
scoreboard[0]=str(Highscore);
scoreboard[1]="why this no work?";
saveStrings("Highscore.txt",scoreboard);
}
Where Highscore is an int in game that holds, you guessed it, the current highscore. And Highscore.txt is a text file in my data folder with one line in it as "0" (zero if your font is wierd)
ignore the comments BTW i stole this from the data tutorial :P
Answers
Have you invoked those functions anyway?! :O)
Moreover, in order to save in the data folder, we gotta use dataPath(""):
Yes, but you did scare me, i had to check :))
Hmm still didnt work...
uh ok. It did work if i add datapath to both savestrings and loadstrings 8-| thanks alot Mr Loop.
Nice it work. Notice that only save functions actually need dataPath(""). It's redundant for load 1s! :P
Actually on android it didnt seem to work without it.
ok nevermind. Your answer doesnt work on the kindle fire? This is strange...
I don't think Android has a dataPath("")! You gotta search other threads for an equivalent solution! :(|)
Notice that load functions search 1st the sketchPath for a file. Only then it looks inside dataPath("").
So if a file is found inside sketchPath already, it won't bother to search for it further! (~~)
I would recommend using a
Table
, which seems to be able to load / save without needingdataPath()
(loadTable()
andsaveTable()
). I believe that this worked on my Kindle Fire as well. Note that the use is a bit different, but the table data structure might be better suited to storing high score data in the first place (I have usedTable
for high scores in the past).In your app, when you save to a table, did you use an absolute path or just the file name?
When saving the
Table
, I was able to use just the file name.i thought i tried that but ill give it another crack.