Posted 27 September 2013 - 09:09 PM
Right, so here's some code snippets from a larger program I'm writing:
As should be reasonably obvious, I'm saving this program as some other file name. On running with parameters (eg. test 5 6), it gets those parameters as variables r and o, and then writes them to the config file. Additionally it copies itself to a startup program.
The problem is that the writing doesn't seem to work. While the print(r, o) returns the correct parameters, the digger.cfg gets written with
function load_cfg()
local file = fs.open("digger.cfg", "r")
local r = tonumber(file.readLine())
local o = tonumber(file.readLine())
file.close()
end
function write_cfg()
local file = fs.open("digger.cfg", "w")
file.writeLine(tostring(r))
file.writeLine(tostring(o))
file.close()
end
--Main body
if (shell.getRunningProgram()~="startup") then
local args = {...}
local r = tonumber(args[1])
local o = tonumber(args[2])
if not (r and o) then
print("No arguments given!")
return
end
local current_x = 0
local current_y = 0
local current_z = 0
local current_f = 0
local resume = false
print(r, o)
write_cfg()
fs.copy(fs.getName(shell.getRunningProgram()), "startup")
else
load_cfg()
local resume = true
end
As should be reasonably obvious, I'm saving this program as some other file name. On running with parameters (eg. test 5 6), it gets those parameters as variables r and o, and then writes them to the config file. Additionally it copies itself to a startup program.
The problem is that the writing doesn't seem to work. While the print(r, o) returns the correct parameters, the digger.cfg gets written with
nil
nil
I can't figure out what I've done wrong here, could anyone help?