This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
neondrop's profile picture

How to avoid a program waiting for the input

Started by neondrop, 18 March 2012 - 03:22 PM
neondrop #1
Posted 18 March 2012 - 04:22 PM
Hi,
sorry if this is a noob question, but I can't figure this out :/
I've written a little program for the turtle, which makes it move until it hits an obstacle. If it hits one, it starts turning around, until the way is free again. Up to now, I used an infinite loop for that, but this isn't a really nice way to go, so I want the turtle to write something like: "Shut this unit down?:" , if you type nothing, the turtle continues to work, if you type "yes", the loop breaks.
My problem is now, that when I use io.read() to get the input, the turtle stops working until I type something in. I hope it's clear what i mean. Basically, I want the turtle to work until i type "yes".

thanks for any help!
Liraal #2
Posted 18 March 2012 - 04:24 PM
os.startTimer(1)
while true do
local event,arg=os.pullEvent(()
if event=="timer" then break end
if event=="char" and arg=="y" then return true end
end
neondrop #3
Posted 18 March 2012 - 04:29 PM
Oh my gawd


That was a fast answer, trying it out now :D/>/>