Posted 30 October 2012 - 06:08 PM
Hey guys, just wanted to know if there is an easier way to check if the ID of a computer of a inputted number actually exists than what I have:
Main PC:
Receiver PC:
This does work nicely but it isn't that ethical.
Main PC:
Spoiler
tMsgs = {
["PCFound"] = "Connected to PC with ID: ",
["PCNotFound"] = "Unable to connect to PC with ID: ",
}
function cls(x,y)
term.clear()
term.setCursorPos(x,y)
end
rednet.open("top")
while true do
repeat
cls(1,1)
write("Enter the ID of the computer you would like to interact with: ")
cID = tonumber(read())
until type(cID) == "number"
print("\nAttemping to connect to PC with ID: "..cID)
sleep(3)
rednet.send(cID,"test")
os.startTimer(0.1)
event, sID, msg, dist = os.pullEvent()
cls(1,1)
if event == "timer" then
print(tMsgs["PCNotFound"]..cID)
elseif event == "rednet_message" then
if msg == "true" then
print(tMsgs["PCFound"]..cID)
end
else print("Event: "..event)
end
sleep(3)
end
Receiver PC:
Spoiler
function cls(x,y)
term.clear()
term.setCursorPos(x,y)
end
rednet.open("top")
while true do
cls(1,1)
print("Waiting for a rednet message...")
event, rID, msg, dist = os.pullEvent("rednet_message")
if msg == "test" then
cls(1,1) print("Received message: "..msg.."\nSending message: true to PC with ID: "..rID)
rednet.send(rID, "true")
end
end
This does work nicely but it isn't that ethical.