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

asked Jun 30 in Projects by DanioDevs (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))

And reading the file

var file = File.new()
file.open("path/to/file.txt", file.READ)
number = int(file.get_line())
answered Jul 1 by Magso (2,713 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.