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

[Lua][Question]Screen Refreshing with os.pullEvent()

Started by exploder, 20 October 2012 - 05:43 PM
exploder #1
Posted 20 October 2012 - 07:43 PM
Hello Computercraft community.

My problem is, that when I add os.pullEvent() to my options screen the computer is waiting for response and screen is not refreshing.(Without os.pullEvent it works fine.)

I want to make time that keep refreshing and computer waiting for response at the same time, so is that possibe?

Here is the code. I didn't include os.pullEvent in the code so you could tell me where should I put it, or how?
Spoiler

id = os.computerID()
pass = "gta"
function access()
term.restore()
term.clear()
term.setCursorPos(1,1)
print("Enter the password")
write("Password:")
input = read("*")
if input == pass then
term.setCursorPos(1,4)
textutils.slowPrint("Password is correct")
sleep(0.7)
term.clear()
term.setCursorPos(1,1)
error()
else
term.setCursorPos(1,4)
textutils.slowPrint("Password is incorrect")
sleep(2)
os.reboot()
end
end
mon = peripheral.wrap("left")
term.redirect(mon)
term.clear()
term.setCursorPos(1,1)
while true do
local time = os.time()
time = textutils.formatTime(time, true)
print[[		 Exploder's House
			 Options:
1.Access Computer.]]  
  
term.setCursorPos(1,10) print("Computer ID:"..id.."") term.setCursorPos(26,10) print("Time "..time) --Here is the time that should keep refreshing.
sleep(0.5) -- Here is the part that refreshes screen every half a second.
term.clear()
term.setCursorPos(1,1)
end

Sorry for my poor English, but I hope you'll understand.
Thank you.
ChunLing #2
Posted 20 October 2012 - 08:49 PM
Use os.startTimer(0.5) and then os.pullEvent() rather than sleep. That way, the computer fires off your timer event after a half second, os.pullEvent gets the timer event, and the program continues. Or there is some other event and that gets pulled instead. Based on the event pulled, you can then do different things.
exploder #3
Posted 21 October 2012 - 07:23 PM
Use os.startTimer(0.5) and then os.pullEvent() rather than sleep. That way, the computer fires off your timer event after a half second, os.pullEvent gets the timer event, and the program continues. Or there is some other event and that gets pulled instead. Based on the event pulled, you can then do different things.

This did the work, thank you.