Jump to content




(Question) Rednet receive forever or until keypress


  • You cannot reply to this topic
2 replies to this topic

#1 dirtywastegash

  • Members
  • 6 posts

Posted 08 May 2012 - 10:14 AM

Trying to get a computer to listen for a rednet signal indefinitely until a key is pressed or input is entered.

the code:
rednet.open(side)
while true do
id, dest = rednet.receive()
if input == "x" then
  break -- will stop the while loop
end
end

Doesn't allow me to break the program...

Also, will using

rs.setBundledOutput(side, color, true)
os.startTimer(1)

cut off the output?

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 08 May 2012 - 10:30 AM

The best way to do this is with events, I would check out the tutorial on os.pullEvent for more details but here is a small example of what you will want to do.

while true do
local event, param1, param2 = os.pullEvent()
if event == "rednet_message" then
--do stuff for the rednet message"
elseif event == "key" then -- will detect any key being pressed and return the key number for example the esc key is 1
if "param1" ~= 1 then -- if anything except esc was pressed
-- do key stuff
end
elseif event == "char" then -- will return which key was pressed
if param1 == "x" then
--do different key stuff
end
end
end


#3 dirtywastegash

  • Members
  • 6 posts

Posted 08 May 2012 - 10:45 AM

Thank you for the quick reply....

This should help me out no end.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users