Posted 27 July 2013 - 09:24 AM
i made redstone pulser program with lua but it doesn't show me anything help me and i am first with coroutine please fix this program it is really simple program
http://pastebin.com/m3C72S8d
http://pastebin.com/m3C72S8d
- function TerminalHandler()
- while true do
- local interval12 = loaddata("interval")
- write(interval12)
- write("interval for timer : ")
- local interval = read()
- local interval1 = {}
- interval1[1] = interval
- savedata(interval1,"interval")
- end
- end
- function timer()
- while true do
- local interval20 = loaddata("interval")
- local interval = interval20[1]
- sleep(interval)
- rs.setOutput("left",true)
- sleep(interval)
- rs.setOutput("left",false)
- end
- end
- function process()
- local c1 = coroutine.create(TerminalHandler)
- local c2 = coroutine.create(timer,interval)
- local eventData = {}
- while true do
- –# resume our routine giving it the event data
- coroutine.resume(c1, unpack(eventData))
- if coroutine.status(c1) == "dead" then
- c1 = coroutine.create(TerminalHandler)
- end
- –# resume our routine giving it the event data
- coroutine.resume(c2, unpack(eventData))
- if coroutine.status(c2) == "dead" then
- c2 = coroutine.create(timer)
- end
- eventData = { coroutine.yield() } –# you could also use os.pullEventRaw here, but again, it is just a wrapper of coroutine.yield, so why not just use the top level function
- end
- end
- function savedata(table,id)
- local file = fs.open(id,"w")
- file.write(textutils.serialize(table))
- file.close()
- end
- function loaddata(id)
- local file = fs.open(id,"r")
- local data = file.readAll()
- file.close()
- return textutils.unserialize(data)
- end
- process()