High score on android

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By JokerDDZ

Hello.

I have no idea how to create such a thing but its really important for my game on android. I just need to store one var. Does anybody know where I can find information about that or kind of tutorial ? ( I mean offline high score , local high score for the player)

Is there any way you can save a “high score” file in the user:// directory? When it’s time for you to record a high score, you compare the recently-earned score to the ones in the"high score" file. If it’s larger than those ones, it gets placed at the top.

I’d flesh this out more, but I’m currently not at computer.

Ertain | 2018-07-23 22:57

:bust_in_silhouette: Reply From: warlockF13

The easiest way I found to do that is by using Dreamlo and HTTPRequests.

This is the official tutorial for using HTTPRequests: Making HTTP requests — Godot Engine (3.0) documentation in English
You have to send a HTTPRequest Dreamlo’s URL as described here: dreamlo - developer

If you need to store more data or want to do it differently you will have to setup a server on websites like Cloudno.de, Heroku, AWS, Google Cloud, Azure, etc…

I am sorry but you missunerstood me. I mean offline high score. Just for the player. No ranking or anything like that. Do you know how to do something like that ? I have seen some tutorials for windows and linux but they doesnt work on android.

JokerDDZ | 2018-07-23 22:27

:bust_in_silhouette: Reply From: kidscancode

Data can be saved in the user:// folder regardless of platform. I have something like the following (simplified for demonstration purposes) working fine in an Android game. It should get you started.

Note: this is a simplified version just saving the single highest score. If you want to save more data, change accordingly.

# filename to store the data - note the path
var score_file = "user://highscore.txt"
var highscore = 0

# call this at the beginning of your game.
# Tests to see if the file exists and loads the contents if it does
func load_score():
    var f = File.new()
    if f.file_exists(score_file):
        f.open(score_file, File.READ)
        var content = f.get_as_text()
        highscore = int(content)
        f.close()

# call this at game end to store a new highscore
func save_score():
    var f = File.new()
    f.open(score_file, File.WRITE)
    f.store_string(str(highscore))
    f.close()

I used this tutorial: https://www.youtube.com/watch?v=EteQMVK2joI
I thing storing data in .txt file is just a bad idea.
BTW
I have watched some your tutorials on youtube.
You are doing great job.
Thank you for your help :slight_smile:

JokerDDZ | 2018-07-26 14:40

You don’t have to use a text file - that was just an example. It really doesn’t matter in what format you save local data, the user will be able to see and alter it.

kidscancode | 2018-07-26 15:17