Trying to countdown from 5 to 0 but also look for a keypress using os.pullEvent("key"). I've managed to get it so that if there is no keypress that it will successfully count all the way down and if there is a keypress that it will cancel the countdown, clear the screen, and NOT continue to print the countdown. However shortly after it clears the screen and prints the new menu it exits out of the script. Not sure why? Maybe someone here could give me a hand! I've tried all sorts of 'return' uses and 'break' uses. Latest endeavor was using a variable to declare the state of the event() function and have the start() function check it routinely.
function test()
end
function event()
runtime = true
os.pullEvent("key")
runtime = false
term.clear()
term.setCursorPos(1,1)
term.setTextColor(1)
term.write("Enter the distance you'd like this CnS bot to dig.")
while true do
local input = io.read()
input = tonumber(distance)
if distance then
break
end
print("Please enter an actual number.")
end
end
function start()
print("By default this CnS bot will mine a distance of 128 blocks")
print("Press any button to change this value")
x, y = term.getCursorPos()
s = 5
while s > 0 do
if runtime == true then
term.setTextColor(8)
term.write(s)
sleep(1)
s = s - 1
term.setCursorPos(x, y)
else
break
end
end
end
parallel.waitForAny(event, start)
--turtle.getFuelLevel(
Anyone's help would be appreciated! Thank you!












