This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Creator's profile picture

IPnet: GPS based IP system for internet protocol in Computercraft

Started by Creator, 31 January 2015 - 08:59 PM
Creator #1
Posted 31 January 2015 - 09:59 PM
Hi guys,

I'm having a little trouble with this piece of code:


function getCientIPs()
while true do
  local event, side, ch1, ch2, msg, distance = os.pullEvent("modem_message")
  if ch1 == 65526 and ch2 == 1 then
   local clientsToAnalyse = {}
   local possibleClients = {}
   possibleClients = textutils.unserialize(msg)
   debugPrint("Possible clients: ")
   debugPrint(textutils.serialize(possibleClients))
   for i,v in pairs(clientIPs) do
    for k,m in pairs(possibleClients) do
	 if  v == m then
	  debugPrint("analyzing...")
	  clientsToAnalyse[k] = true
	 end
    end
   end
   debugPrint("Clients to analyze: ")
   debugPrint(textutils.serialize(clientsToAnalyse))
   for i,v in pairs(clientsToAnalyse) do
    if v ~= true or v == nil then
	 debugPrint("v: ")
	 debugPrint(v)
	 clientIPs[#clientIPs + 1] = possibleClients[i]
	 debugPrint("ClientIPs: ")
	 debugPrint(textutils.serialize(clientIPs))
    end
   end
  end
end
end

What it does is that it takes the table it receives from a slaveRouter with all the client IPs of the slave routers. ClientIPs reffers to the already stored ids. The table is empty in the begining. DebugPrint prints the argument if debugOpt == true. Only for debugging. So the code is not working properly. If you want the whole code just check out this website. The three programs you need start with IPnet. I hope you can help me.

Thanks in advance. :)/>
Rougeminner #2
Posted 31 January 2015 - 10:21 PM
what seems to be your error. can you write it down so we know what to look for in the code?
Creator #3
Posted 01 February 2015 - 09:27 AM
The error is that when it tries to print the clientips table it only prints {}. Does it have anything tobdo with the fact that the in pairs function does not workn on empty tables