SHARE
TWEET

ComputerCraft Tutorial: ex_turtle_select 0_2

hevohevo Jan 25th, 2014 413 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- #######################################
  2. -- ex_turtle_select
  3. -- (extend Turtle API program)
  4. -- version 0.2
  5. -- http://hevohevo.hatenablog.com/
  6.  
  7. -- #######################################
  8. -- add new functions in Turtle API
  9. -- turtle.select_org(n)
  10. -- turtle.select(n)
  11. -- turtle.getSelectedSlot()
  12. -- turtle.selectNext()
  13. -- turtle.selectPrev()
  14.  
  15. if turtle then
  16.   turtle.select_org = turtle.select_org or turtle.select
  17.  
  18.   turtle.select = function(slot)
  19.     turtle.select_org(slot)
  20.    
  21.     local func = function (x)
  22.         slot = slot + x
  23.         return (((slot-1) % 16)+1)
  24.     end
  25.    
  26.     turtle.selectNext = function() return turtle.select_org(func(1)) end
  27.     turtle.selectPrev = function() return turtle.select_org(func(-1)) end
  28.     turtle.getSelectedSlot = function() return func(0) end
  29.    
  30.     return true
  31.   end
  32.   turtle.select(1)
  33.   print("  extend API: turtle.select*")
  34. end
RAW Paste Data
Top