Here's the code for a screensaver code I'm writing. It is supposed to randomly draw pixels on the screen until a key is pressed. The problem is, it doesn't exit when you press a key, and cannot be terminated.
local maxX, maxY = term.getSize()
local count = 1
term.clear()
while true do
local function screensaver()
local xPos = math.random(1,maxX)
local yPos = math.random(1,maxY)
term.setCursorPos(xPos,yPos)
local txtColor = 2^math.random(0,15)
term.setBackgroundColor(txtColor)
write(" ")
count = count+1
sleep(0.1)
if count == 250 then
count = 1
term.setBackgroundColor(colors.black)
term.clear()
end
end
local function exit()
while true do
sleep(0.1)
event = os.pullEvent()
if event == "char" then
term.clear()
term.setCursorPos(1,1)
error()
end
end
end
parallel.waitForAny(screensaver, exit)
end
Any help is appreciated. Thanks!
--Dlcruz











