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

key detection while running program

Started by LightsDawn, 24 December 2014 - 11:14 AM
LightsDawn #1
Posted 24 December 2014 - 12:14 PM
hey, im trying to make my computer detect any keystroke from the keyboard so it breaks a loop but i want it to keep going through the loop while its detecting if i pressed a key. my code goes something like this:

function rsAnalog()
local rsread = rsRead()
while true do
clear()
monClear()
local rsIn = rs.getAnalogInput("back")
if rsIn <= tonumber(rsread) then
rs.setOutput("right", true)
sleep(3)
else rs.setOutput("right",false)
end

rsRead is another function that returns a key that i press to make the rsIn output redstone signal until the redstone power thats behind it is = to that number i put in. im trying to make the computer exit this loop upon keypress and since i have while true do function rsAnalog() at the bottom it will just enter the loop again and ask me for a number. thats my end goal, have it restart this rsAnalog loop upon keypress
KingofGamesYami #2
Posted 24 December 2014 - 03:37 PM
Please post the full code - including the rsRead function. Let me see if you want to do what I think:

Upon keypress, pause loop
Upon another keypress resume loop