How Do i save an interger variable

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

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

:bust_in_silhouette: Reply From: Magso

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()

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

DanioDevs | 2020-07-01 16:07

“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

Magso | 2020-07-01 18:39