162 posts
Posted 27 January 2014 - 05:10 PM
I plan on making a program and a partner program/API to go with it. This whole plan is dependent on whether or not you can do what I want to do. Basically here's what I want to do. So, program one, lets say it's a multi-purpose program. When you first run it you get a couple options on what it can do. Let's say there's a variable that starts at 1 and makes it show the menu but when you select an option it changes that variable. Forever. Like, if I were to turn off both programs the variable will not have changed back to 1. Is there a way to make that happen?
1281 posts
Posted 27 January 2014 - 05:19 PM
Just store the variable to a file using the fs.api, then read it on startup.
local variable = "derp"
local file = fs.open("fileName","w") -- note the "w", this means write mode, for writing to files. This will delete the current file or create a new one, and write whatever you tell it to.
file.writeLine(variable) -- write the variable to a line in the file
file.close() -- finished writing, close the file
local file = fs.open("fileName","r") -- "r" is read mode, which obviously is used to read the file.
variable = file.readLine() -- returns one line of the file everytime it is called.
file.close() --done reading, close the file
31 posts
Posted 27 January 2014 - 05:19 PM
well yes and no but you are probably better of saving your variable to a file with fs.open() take a look at this
http://computercraft.info/wiki/Fs.open and just read the contents back to the variable when you reload