Posted 26 September 2012 - 04:55 AM
What I need to do, is iterate through a for loop, while collecting data from a save file. This save file has the values of my bundled cables, whether they are on or not. Currently, by function is failing, because it will iterate through the loop, collecting the correct data, and then all hell breaks loose….
I'll post my function here that's having the problem:
Here is my loadState() function:
And here is my status file:
As it is right now, it will iterate through, and for testing I put in the print and sleep functions. It will turn on the correct cables as it iterates, but it will then set to another cable the next color down. I thought that colors.combine() would fix that…obviously I'm wrong. I need the colors that it retrieves to be collected somehow, and then add the values AFTER the iteration, instead of during. How would I do that?
I'll post my function here that's having the problem:
Spoiler
local function resume()
controlTable = loadState()
local colorTable = {}
for eNum, dInfo in ipairs(controlTable) do
for i = 1,#machineList do
if dInfo.type == machineList[i] then
if dInfo.type == "Reactor" or dInfo.type == "Coolant" then
if dInfo.status == "false" and dInfo.color ~= "false" then
print(dInfo.type..", "..dInfo.color..", "..dInfo.status)
sleep(1)
rs.setBundledOutput("back",colors.combine(tonumber(dInfo.color)))
elseif dInfo.status == "true" and dInfo.color ~= "false" then
print(dInfo.type..", "..dInfo.color..", "..dInfo.status)
sleep(1)
rs.setBundledOutput("back",colors.subtract(tonumber(dInfo.color)))
end
else
if dInfo.status == "false" and dInfo.color ~= "false" then
print(dInfo.type..", "..dInfo.color..", "..dInfo.status)
sleep(1)
rs.setBundledOutput("back",colors.subtract(tonumber(dInfo.color)))
elseif dInfo.status == "true" and dInfo.color ~= "false" then
print(dInfo.type..", "..dInfo.color..", "..dInfo.status)
sleep(1)
rs.setBundledOutput("back",colors.combine(tonumber(dInfo.color)))
end
end
end
end
end
end
Spoiler
local function loadState()
local loadTable = {}
local file = fs.open(".MCS/status", "r")
if file then
readLine = file.readLine()
while readLine do
local lineTable = {}
lineTable.type, lineTable.color, lineTable.status = string.match(readLine, "(%w+),(%w+),(%w+)")
if lineTable.type then
table.insert(loadTable, lineTable)
end
readLine = file.readLine()
end
file.close()
end
return loadTable
end
Spoiler
Admin,craniumkid22,xxxxx
User,miveck,xxxxx
Lights,1,true
IndustrialCraft2,true,true
Power,2,false
Reactor,16384,false
Coolant,2048,false
MFSU,redstone,None
Macerator,false,false
Furnace,false,false
Compressor,false,false
Extractor,false,false
RedPower2,true,true
RedPowerPump,false,false
Blockbreaker,false,false
Buildcraft,true,true
MiningWell,false,false
Quarry,false,false
BuildcraftPump,false,false
Forcefield,2,false
Firstrun,completed,true