We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all! Hope you're having a good day.
I recently made an android game and I want to be able to save a high score. I've tried looking at other discussions on this forum but I couldn't find anything relevant to Android mode. Most of it was to do with Java mode. If it's relevant, I only need to save a single number at any one point in time.
Here are the steps that I believe I need to take in order to create a high score:
Upon opening the app, check if a highscore.txt file is saved and if so, load it. Otherwise, create a new highscore.txt file with its only content being '0'.
Upon 'death', aka playing and losing the game, compare the number in the highscore.txt file against the current score.
Overwrite the highscore.txt file with the higher score.
My score is an int value named currentScore.
I've tried tinkering around to implement it myself, but I don't know where to start with permissions and everything.
Any help would be greatly appreciated! Have a nice day :)
Answers
Check this https://forum.processing.org/two/discussion/comment/105543/#Comment_105543
Kf
Hey thank you I'll check it out!
Hey kfrajer, I looked through your resources as thoroughly as I could, and I managed to finish steps 1 and 2, but I'm still having trouble overwriting my highscore.txt file.
I'm trying to use saveStrings() to save the txt file in a folder /data/user/0/com.packagename1.packagename2/files. When I run the program again it still uses the original highscore.txt file instead of the overwritten version, which leads me to think that there is a problem with my saveStrings() function.
Here is the relevant portion of my code:
highscoreString = str(currentScore); String [] latesthighscore = split(highscoreString, ' '); saveStrings("highscore.txt", latesthighscore);
@OliverC===
fo this kind of things Android API savePreferences is your friend!
see here: https://developer.android.com/training/data-storage/shared-preferences.html
Hey thanks @akenaton! Works like a charm now :)