I've been making a turtle quarry with mining wells and tesseracts…. but when my controller registers the turtles, i want them to be in order ( lowest computer id to highest )
EDIT: Look in the comment on 2nd page for my new problem
but this is ending in "invalid key to 'next'" on line 60 ( which is for k,v in pairs(database) )
my code:
local screen={term.getSize()}
local modem = peripheral.wrap("right")
modem.open(25563)
modem.open(25564)
local database={}
local databaseControllers={}
function split(s, delimiter)
result = {};
for match in (s..delimiter):gmatch("(.-)"..delimiter) do
table.insert(result, match);
end
return result;
end
print("Remote-rebooting miners...")
modem.transmit(25564,25563,"reboot")
print("Waiting 2 seconds for miners to boot up...")
sleep(2)
term.clear()
term.setCursorPos(1,1)
print(string.rep("=",screen[1]))
--Register turtles...
print("Pinging...")
modem.transmit(25564,25563,"ping")
print("Pinged! Waiting for response...")
timeout=os.startTimer(10)
while true do
local oldPos={term.getCursorPos()}
term.setCursorPos(1,1)
print(string.rep("=",screen[1]))
term.setCursorPos(oldPos[1],oldPos[2])
local event,t1,sender,receiver,response,distance=os.pullEvent()
if event == "modem_message" then
if sender == 25563 then
tbl=split(response," ID=")
--TYPE -- ID
if tbl[1] == "miner" then
database[tbl[2]]=tbl[2]
print("Registered miner with ID "..tbl[2])
elseif tbl[1] == "controller" then
databaseControllers[tbl[2]] = tbl[2]
print("Registered controller with ID "..tbl[2])
end
print(response)
elseif sender == 00001 then
print(response)
end
elseif event == "timer" then
if t1 == timeout then
break
end
end
end
------------------------- Errors below this line --------------------------------------
print("DONE")
rTbl={}
local currentValue=20000
--print(textutils.serialize(database))
--sleep(3)
for k,v in pairs(database) do
if tonumber(k) < currentValue then
currentValue=k
table.insert(rTbl,k)
database[k]=nil
end
end
for k,v in ipairs(rTbl) do
print(k.." - "..v)
sleep(0.5)
end
Thanks in Advance