Guest User

test2

a guest
Jul 27th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.52 KB | None | 0 0
  1. function TerminalHandler()
  2. while true do
  3. local interval12 = loaddata("interval")
  4. write(interval12)
  5. write("interval for timer : ")
  6. local interval = read()
  7. local interval1 = {}
  8. interval1[1] = interval
  9. savedata(interval1,"interval")
  10. end
  11. end  
  12. function timer()
  13.   while true do
  14.   local interval20 = loaddata("interval")
  15.   local interval = interval20[1]
  16.   sleep(interval)
  17.   rs.setOutput("left",true)
  18.   sleep(interval)
  19.   rs.setOutput("left",false)
  20.   end  
  21. end  
  22. function process()
  23.   local c1 = coroutine.create(TerminalHandler)
  24.   local c2 = coroutine.create(timer,interval)
  25.   local eventData = {}
  26.  
  27.   while true do
  28.         --# resume our routine giving it the event data
  29.         coroutine.resume(c1, unpack(eventData))
  30.  
  31.         if coroutine.status(c1) == "dead" then
  32.           c1 = coroutine.create(TerminalHandler)
  33.         end
  34.  
  35.         --# resume our routine giving it the event data
  36.         coroutine.resume(c2, unpack(eventData))
  37.  
  38.         if coroutine.status(c2) == "dead" then
  39.           c2 = coroutine.create(timer)
  40.         end
  41.  
  42.         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
  43.   end  
  44. end
  45. function savedata(table,id)
  46.   local file = fs.open(id,"w")
  47.   file.write(textutils.serialize(table))
  48.   file.close()
  49. end
  50. function loaddata(id)
  51.   local file = fs.open(id,"r")
  52.   local data = file.readAll()
  53.   file.close()
  54.   return textutils.unserialize(data)
  55. end      
  56.  
  57.  
  58. process()
Advertisement
Add Comment
Please, Sign In to add comment