Posted 28 July 2014 - 04:54 PM
Hey guys writing a networking program for my base and having what im sure is probably a small issue with this function.
This is the server code and is looking for a response from a client computer on the network. The message is received fine however for some reason the code wont iterate though the table properly (no error). The goal is to check whether or not the client responding is already in the table of clients or not. The signals and output work fine without the for loops but with them the printed text within them isn't shown at all not even the stuff in else.
Bit tired so it might just be a small oversight (only started learning lua 2 days ago).
Cheers,
Ozy
This is the server code and is looking for a response from a client computer on the network. The message is received fine however for some reason the code wont iterate though the table properly (no error). The goal is to check whether or not the client responding is already in the table of clients or not. The signals and output work fine without the for loops but with them the printed text within them isn't shown at all not even the stuff in else.
Bit tired so it might just be a small oversight (only started learning lua 2 days ago).
function response() -- Wait for broadcast responses from the clients.
while true do
id, message = rednet.receive()
if message == "here!" then
for k, v in pairs(clients) do
for k, v in pairs(clients[k]) do
if v == id then
print("Computer ID: "..id.."already connected")
else
local i = 1
print("INFO: Computer ID: "..id.." connected!") -- Print this message only if the computer is not already in the system
clients[i] = {id, "connected"}
i = i + 1
end
end
end
end
end
end
Cheers,
Ozy