-Print out a text
-Wait for key input/handle keyinput
-Redstone flickering
I want to use coroutines !!!!
This is my solution but it kinda doesn't work:
Spoiler
update = false
shouldRender = true
running = true
function clear()
term.clear()
term.setCursorPos(1,1)
end
function render()
while running do
if shouldRender then
clear()
print("+------------------+")
print("| PJOG Section Lua |")
print("| Redstone Furnace |")
print("+------------------+--------+")
print("| Druecke <g> um zu starten |")
print("| Druecke <s> um zu stoppen |")
print("+---------------+-----------+")
print("| Im Moment <"..(update and "R" or "S").."> |")
print("+---------------+")
shouldRender = false
end
end
end
function tick()
while running do
if update then
rs.setOutput("bottom", true)
sleep(1)
rs.setOutput("bottom", false)
end
sleep(0)
end
end
function waitFor()
while running do
e = {os.pullEvent()} --coroutine.yield
if e[1] == "char" then
if e[2] == "g" then
update = true
shouldRender = true
elseif e[2] == "s" then
update = false
shouldRender = true
elseif e[2] == "q" then
running = false
end
end
end
end
function time()
while running do
str = os.day.." "..textutils.formatTime(os.time(), true)
w,h = term.getSize()
term.setCursorPos(w-str:len(),h-1)
term.write(str)
end
end
local renderThread = coroutine.create(render)
local updateThread = coroutine.create(waitFor)
local actionThread = coroutine.create(tick)
local timer = coroutine.create(time)
function main()
while running do
e = {os.pullEvent()}
resume = coroutine.resume(updateThread, unpack(e))
coroutine.resume(renderThread)
coroutine.resume(actionThread)
coroutine.resume(timer)
end
end
main()