Pinkishu

Untitled

Jun 30th, 2012
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | None | 0 0
  1. local side = "left"
  2. local funcState = {}
  3. funcState.step = 0
  4. funcState.func = runLeft
  5. local rsDelay = 0.1
  6.  
  7. function funcDo()
  8.   print("CALL")
  9.   local res = funcState.func()
  10.   print("CALL")
  11.   if res == "#END" then
  12.   end
  13.  
  14.   delay(rsDelay)
  15. end
  16.  
  17. local funcCo = coroutine.create(funcDo)
  18.  
  19.  
  20. local colMap = {
  21.   headSliderBreaker = { color = colors.magenta, delay = 2 },
  22.   headSliderLeft = { color = colors.orange, delay = 5 }
  23. }
  24.  
  25. function redclear()
  26.   rs.setBundledOutput(side,0)
  27. end
  28.  
  29. function redset(color)
  30.   rs.setBundledOutput(side,color)
  31. end
  32.  
  33. function redadd(color)
  34.   --print("add " .. color )
  35.   local nCol = colors.combine( rs.getBundledOutput( side ), color )
  36.   rs.setBundledOutput(side,nCol)
  37. end
  38.  
  39. function reddel(color)
  40.   --print("sub " .. color )
  41.   local nCol = colors.subtract( rs.getBundledOutput( side ), color )
  42.   rs.setBundledOutput(side,nCol)
  43. end
  44.  
  45. function redtest(color)
  46.   return colors.test( rs.getBundledInput( side ), color )
  47. end
  48.  
  49. function delay(delayt)
  50.   funcState.timer = os.startTimer( delayt )
  51.   coroutine.yield()
  52. end
  53.  
  54. function redpulse(opts)
  55.   redadd(opts.color)
  56.   delay( opts.delay )
  57.   reddel(opts.color)
  58.   delay(rsDelay)
  59. end
  60.  
  61. function mineHeadLeft()
  62.   print("left")
  63.   redpulse(colMap.headSliderBreaker)
  64.   redpulse(colMap.headSliderLeft)
  65.   print("leftEnd")
  66. end
  67.  
  68. redclear()
  69.  
  70. function runLeft()
  71.   print("tt")
  72.   while not redtest(colors.white) do
  73.     mineHeadLeft()
  74.   end
  75.   return "#END"
  76. end
  77. funcState.func = runLeft
  78.  
  79. function timerCallback(ev,p1)
  80.   if p1 == funcState.timer then
  81.     funcState.timer = nil
  82.     print("resuming")
  83.     coroutine.resume(funcCo)
  84.     if funcState.func() == "#END" then
  85.       funcEnd()
  86.     end
  87.   end
  88. end
  89.  
  90. events.registerEvent("timer",timerCallback)
  91. coroutine.resume(funcCo)
  92. while true do
  93.   coroutine.yield()
  94.  
  95. end
Advertisement
Add Comment
Please, Sign In to add comment