Posted 28 October 2012 - 05:01 PM
Hey there,
I am working on a list of programs working together.
So far I got my "manager" program, my "quarry" and my "input".
The Manager keeps track of what places need to be dug and when a turtle asks for a place to dig, it assigns it.
The Quarry tells the turtle how to handel the information given by the Manager, basically telling it how to dig.
The Input allows me to add new areas to be dug to my manager, so I dont have to shut it down to keep it running.
They are all running smooth and without flaws.
I just got the idea to store my quarry areas in a Saved Variable so my manager will remember them even if he gets shutdown.
I managed to get the file to store the first location, but as soon as I add additional locations, it fails (no lua error, the numbers are just not added to my .txt file).
Some Variables:
This is my part of the code that runs the save
I am working on a list of programs working together.
So far I got my "manager" program, my "quarry" and my "input".
The Manager keeps track of what places need to be dug and when a turtle asks for a place to dig, it assigns it.
The Quarry tells the turtle how to handel the information given by the Manager, basically telling it how to dig.
The Input allows me to add new areas to be dug to my manager, so I dont have to shut it down to keep it running.
They are all running smooth and without flaws.
I just got the idea to store my quarry areas in a Saved Variable so my manager will remember them even if he gets shutdown.
I managed to get the file to store the first location, but as soon as I add additional locations, it fails (no lua error, the numbers are just not added to my .txt file).
Some Variables:
local s = {}
local dataJobList = "disk/managerJobList.txt"
local fileSave = fs.open(dataJobList, "w")
local fileLoad = fs.open(dataJobList, "r")
local jobTypeText = {"Quarry","Tunnel"}
local jobTypeInfo = {6,0}
local jobInfo0 = {} -- JobType
local jobInfo1 = {} -- xCoord Start
local jobInfo2 = {} -- zCoord Start
local jobInfo3 = {} -- yCoord Start
local jobInfo4 = {} -- Extra info 1
local jobInfo5 = {} -- Extra info 2
local jobInfo6 = {} -- Extra info 3
This is my part of the code that runs the save
-- Save
function save()
-- Wipes old s variables
for i = 1, 9 do
s[i] = ""
end
-- Convert first data to string
s[1] = tostring(jobNumberTotal)
s[2] = tostring(jobNumberCurrent)
-- Convert our table values into strings
for i = 1, jobNumberTotal do
s[3] = s[3]..tostring(jobInfo0[i]).." "
s[4] = s[4]..tostring(jobInfo1[i]).." "
s[5] = s[5]..tostring(jobInfo2[i]).." "
s[6] = s[6]..tostring(jobInfo3[i]).." "
s[7] = s[7]..tostring(jobInfo4[i]).." "
s[8] = s[8]..tostring(jobInfo5[i]).." "
s[9] = s[9]..tostring(jobInfo6[i]).." "
end
-- Making sure we end up with one long string
for i = 3, 9 do
s[i] = tostring(s[i])
end
-- Write the strings to the save
for i = 1, 9 do
fileSave.write(s[i].."n")
end
-- Close the File
fileSave.close()
end