Posted 17 August 2017 - 02:04 AM
Hi all, I recently had a question here http://www.computercraft.info/forums2/index.php?/topic/28877-computercraft-simple-program-not-working-correctly/page__p__268746__hl__grumpycrouton__fromsearch__1
to which I got some help solving an issue I was having.
With all of the new things I learned from that post, I decided to rewrite my code.
Along with this rewrite, came some new issues that I'm not sure how to handle.
Here is my new code:
Server:
Client:
I feel much better about this code, however I am having a pretty strange issue.
When I start the clients, I get a message "Waiting for input…" as expected - and then I start the server.
When I start the server, the client gets an error, but the server keeps going, doing it's thing.
On the client I get this error:
"client:19: Invalid side."
I get this error because for some reason the server sends a message that is like "table: ########" (where the number signs are random numbers/letters) like the following screenshots:
http://prntscr.com/g9fguz
http://prntscr.com/g9fgww
http://prntscr.com/g9fgyj
I'm not really sure why this is happening, but I would love any advice anyone can give me
to which I got some help solving an issue I was having.
With all of the new things I learned from that post, I decided to rewrite my code.
Along with this rewrite, came some new issues that I'm not sure how to handle.
Here is my new code:
Server:
print("Starting server")
sleep(2) --# Give the other computers time to turn on.
rednet.open("left")
local clients = {rednet.lookup("lightControl")}
local sides = {"left", "top", "right", "bottom", "back"}
print("Checking clients")
if next(clients) == nil then
error("No clients found!")
end
print("Starting loop")
while true do
if rs.getInput("back") then
local client = clients[math.random(#clients)]
local side = sides[math.random(#sides)]
rednet.broadcast("Off")
print("All lights toggled off.")
rednet.send(client, side)
print(client.." "..side.." light enabled > play")
sleep(10)
else
for i=1,#clients do
rednet.broadcast("Off")
print("All lights toggled off.")
for s=1,#sides do
print(clients[i].." "..sides[s].." tripped > strobe")
rednet.send(clients[i], sides[s])
sleep(.5)
rednet.send(clients[i], "Off")
end
end
end
os.pullEvent("redstone")
end
Client:
rednet.open("front")
rednet.host("lightControl", os.getComputerLabel())
local sides = {"left", "top", "right", "bottom", "back"}
while true do
print("Waiting for input...")
local id, message = rednet.receive()
message = tostring(message)
print("Message recieved: "..message)
if message == "Off" then
print("Light toggled off")
for s=1,#sides do
rs.setOutput(sides[s], false)
end
else
print(message.."light toggled on")
rs.setOutput(message, true)
end
end
I feel much better about this code, however I am having a pretty strange issue.
When I start the clients, I get a message "Waiting for input…" as expected - and then I start the server.
When I start the server, the client gets an error, but the server keeps going, doing it's thing.
On the client I get this error:
"client:19: Invalid side."
I get this error because for some reason the server sends a message that is like "table: ########" (where the number signs are random numbers/letters) like the following screenshots:
http://prntscr.com/g9fguz
http://prntscr.com/g9fgww
http://prntscr.com/g9fgyj
I'm not really sure why this is happening, but I would love any advice anyone can give me