This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Boss Nomad's profile picture

variable change

Started by Boss Nomad, 29 December 2012 - 07:15 AM
Boss Nomad #1
Posted 29 December 2012 - 08:15 AM
Possible to change variable and save it, example if i reboot my computer that variable is still in my program what was there last time.
diegodan1893 #2
Posted 29 December 2012 - 08:46 AM
You have to save it to a file. To do that you can do:

hWrite = fs.open("fileName", "w") --Where filename is the name of the file in whitch you want to save the variable and w open the file in write mode.
hWrite.writeLine(variable) --variable is you variable to save
hWrite.close() --This is important, if you don't close the file it won't work
---------------------------------------------------------------
--To get your variable again you can do:
hRead = fs.open("fileName", "r") --"r" is read mode
variable = hRead.readLine() --It will return the variable (as a string)
hRead.close()