0 votes

So im making a clicker game for android, (school project) and i want to know how could i save an integer variable to a file, nothing else, just one integer if someone knows then please could you tell me, i only started coding about 4 months ago

in Projects by (20 points)

1 Answer

0 votes

You could use a .txt file for this

var file = File.new()
file.open("path/to/file.txt", file.WRITE)
file.store_line(str(your integer))
file.close()

And reading the file

var file = File.new()
file.open("path/to/file.txt", file.READ)
number = int(file.get_line())
file.close()
by (3,214 points)

can the integer be interchangeable with a variable that inclues an integer, thank you for answering btw

"variable that includes an integer"? A variable is either an integer or isn't. the int(file.get_line()) method will return a type int, which an int variable can be set to.

Here's a sample to understand the different datatypes.

var line_text : String
var number : int
line_text = file.get_line() #gets the line as a string
number = int(line_text) #converts string into an int if the string only has characters 0-9
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.

Categories