daily pastebin goal
31%
SHARE
TWEET

ComputerCraft Tutorial: ex_turtle_select 0_1

hevohevo Jan 10th, 2014 756 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.1
  5. -- http://hevohevo.hatenablog.com/
  6.  
  7. -- #######################################
  8. -- add new functions and a value in Turtle API
  9. -- turtle.org_select(n)
  10. -- turtle.select(n)
  11. -- turtle.getSelectedSlot()
  12. -- turtle.selectNext()
  13. -- turtle.selectPrev()
  14. -- turtle._selected_slot  <- this is a private value. don't change directly.
  15.  
  16. if turtle and (turtle.org_select==nil) then
  17.   turtle.org_select = turtle.select
  18.   turtle.org_select(1)
  19.   turtle._selected_slot = 1        
  20.  
  21.   turtle.getSelectedSlot = function()
  22.     return turtle._selected_slot
  23.   end
  24.  
  25.   turtle.select = function(slot)
  26.     if turtle.org_select(slot) then
  27.       turtle._selected_slot = slot
  28.       return true
  29.     else
  30.       return false
  31.     end
  32.   end
  33.  
  34.   local ring1_16 = function(num) -- 1=>1, 16=>16, 17=>1, 0=>16
  35.     if (num % 16) == 0 then
  36.       return 16
  37.     else
  38.       return (num % 16)
  39.     end
  40.   end
  41.  
  42.   turtle.selectNext = function()
  43.     turtle.select(ring1_16(turtle.getSelectedSlot() + 1))
  44.   end
  45.  
  46.   turtle.selectPrev = function()
  47.     turtle.select(ring1_16(turtle.getSelectedSlot() - 1))
  48.   end
  49.   print("completed: extend turtle.select")
  50. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top