Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --This is a test
- --Variables:
- var1 = 0
- var2 = 0
- varStorage = {}
- --Functions:
- function storeVariables()
- varStorage.var1 = var1
- varStorage.var2 = var2
- --The above stores the variables in the table
- local output = textutils.serialize(varStorage)
- --This converts the table to a string
- local handle = assert(fs.open("vars", "w"), "Couldn't save vars")
- handle.write(output)
- handle.close()
- end
- function getVariables()
- local handle = assert(fs.open("vars", "r"), "Couldn't load vars")
- local input = handle.readAll()
- handle.close()
- local destination = textutils.unserialize(input)
- var1 = destination.var1
- var2 = destination.var2
- end
- --Main program:
- getVariables()
- print(var1) print(var2)
- term.write("Enter var1: ") var1 = io.read()
- term.write("Enter var2: ") var2 = io.read()
- storeVariables()
- print(var1) print(var2)
Advertisement
Add Comment
Please, Sign In to add comment