Posted 05 October 2012 - 06:26 PM
Hello, so i am making a program with rednet (first time) and i am having some trouble getting it to read inputs without freezing my loop.
This is the part that sends a message this (should) be working.
This is the part that receives and the place where i am getting trouble
This is the part giving me a hard time because it enjoys pausing the code until i send a new message to it, and i just can't get it to wait shortly (.2 seconds), and then go on if it gets nothing or go out of the loop and await my go.
This is the part that sends a message this (should) be working.
rednet.open("left")
while true do
term.clear()
term.setCursorPos(1,1)
write("Input: ")
write("")
input = read()
if input == "a" then
rednet.send(1,"1")
elseif input == "b" then
rednet.send(1,"2")
elseif input == "c" then
rednet.send(1,"3")
end
end
This is the part that receives and the place where i am getting trouble
rednet.open("left")
local function clock()
print("1")
os.sleep(.2)
print("2")
os.sleep(.2)
local evt, id, msg = os.pullEvent("rednet_message")
if msg == "" then
clock()
elseif msg == "2" then
end
end
while true do
term.clear()
term.setCursorPos(1,1)
print("Waiting")
local evt, id, msg = os.pullEvent("rednet_message")
if msg == "1" then
clock()
elseif msg == "2" then
print("LOL NOPE") -- I enjoy making silly things :(/>/>
os.sleep(.5)
end
end
This is the part giving me a hard time because it enjoys pausing the code until i send a new message to it, and i just can't get it to wait shortly (.2 seconds), and then go on if it gets nothing or go out of the loop and await my go.
local evt, id, msg = os.pullEvent("rednet_message")
if msg == "" then
clock()
elseif msg == "2" then
end