Guest User

gomma

a guest
Jan 19th, 2013
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. -- arriva fino al prossimo tronco e ci si ferma davanti.
  2. -- ritorna true se trova tronco o false se trova cancello
  3. passi = 0
  4. unloaded = 0
  5. tempo=0
  6.  
  7. local function scarica()
  8.     print( "Scaricando Oggetti..." )
  9.     for n=3,16 do
  10.         unloaded = unloaded + turtle.getItemCount(n)
  11.         turtle.select(n)
  12.         turtle.drop()
  13.     end
  14.     collected = 0
  15.     turtle.select(1)
  16. end
  17.  
  18.  
  19. function prossimoTronco()
  20.         -- selezione il recinto, se davanti c'åA8 un recinto, si torna indietro
  21.         turtle.select(2)
  22.         if turtle.compare() then return false end
  23.        
  24.         -- seleziona il tronco d'albero, ritorna vero se trova un albero
  25.         while not turtle.compare()  do
  26.             turtle.forward()
  27.             passi = passi + 1
  28.             turtle.select(2)
  29.             if turtle.compare() then return false end
  30.             turtle.select(1)           
  31.         end
  32.         return true
  33. end
  34.  
  35. function cambiaLato()
  36.         turtle.turnLeft()
  37.         turtle.forward()
  38.         turtle.turnRight()
  39.         turtle.forward()
  40.         turtle.turnRight()
  41. end
  42.  
  43. function succhiaGiu()
  44.     while not turtle.detectDown() do
  45.         turtle.down()
  46.         turtle.dig()
  47.     end
  48. end
  49.  
  50. function tornaDavanti()
  51.     turtle.turnRight()
  52.     turtle.forward()   
  53.     turtle.turnLeft()
  54.     turtle.forward()
  55.     turtle.turnRight()
  56.     passi = passi + 2  
  57. end
  58.  
  59. -- succhia ogni blocco di ogni lato del tronco poi gira davanti al tronco
  60. function succhiaSu()
  61.         while turtle.compare() do
  62.             turtle.dig()
  63.             turtle.up()
  64.         end
  65. end
  66.  
  67. -- ritorna alla base e deposita la gomma
  68. function tornaIndietro()
  69.     turtle.turnRight()
  70.     turtle.forward()
  71.     turtle.turnRight()
  72.  
  73.     for i= 0, passi do
  74.         turtle.forward()
  75. --      print ("passo # " .. i)
  76.     end
  77.     turtle.turnRight()
  78.     turtle.forward()
  79.     turtle.turnRight()
  80. end
  81.  
  82. function succhiaAlbero()
  83.     succhiaSu()
  84.     cambiaLato()
  85.     succhiaGiu()
  86.     cambiaLato()
  87.     succhiaSu()
  88.     cambiaLato()
  89.     succhiaGiu()
  90.     tornaDavanti()
  91. end
  92.  
  93. function tornaPosizione()
  94. turtle.turnLeft()
  95. turtle.forward()
  96. turtle.turnRight()
  97. turtle.forward()
  98. turtle.forward()
  99. turtle.turnRight()
  100. turtle.forward()
  101. turtle.turnLeft()
  102. end
  103.  
  104.  
  105.  
  106. vai = true
  107. while vai do
  108.     passi = 0
  109.     while prossimoTronco() do
  110.         succhiaAlbero()
  111.     end
  112.     passi = passi + 1
  113.     tornaIndietro()
  114.     scarica()
  115.     tornaPosizione()
  116.     sleep(3600)
  117. end
Add Comment
Please, Sign In to add comment