Advertisement
Guest User

Untitled

a guest
Jun 30th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. -- This program will allow a turtle to build a wall,
  2. -- you must give the turtle enough blocks to build the wall.
  3.  
  4. -- Usage: wall.lua length height
  5.  
  6. input = {...}
  7. Largeur = tonumber(input[1])
  8. Longueur = tonumber(input[2])
  9.  
  10. -- The starting slot to look for building materials (from left to right, top to bottem)
  11. --ie. 1 2 3
  12. -- 4 5 6
  13. -- 7 8 9
  14. currentSlot = 2
  15.  
  16. -- This is a function, it is peice of script that we will run later.
  17. -- If this inventory slot runs out of building blocks, move to the next slot.
  18.  
  19. function checkFuel(currentSlot)
  20. if turtle.getFuelLevel() <= 100 then
  21. if turtle.getItemCount(1) == 0 then
  22. print("Out of fuel.")
  23. exit()
  24. else
  25. turtle.select(1)
  26. turtle.refuel(1)
  27. turtle.select(currentSlot)
  28. end --if
  29. end --if
  30. end --checkFuel()
  31.  
  32. function gotoNextSlotIfEmpty()
  33. if turtle.getItemCount(currentSlot) == 0 then
  34. currentSlot = currentSlot + 1
  35. turtle.select(currentSlot)
  36. end
  37. end
  38.  
  39. -- This is where the code starts running.
  40. turtle.select(currentSlot)
  41.  
  42. for la = 1, Largeur do
  43.  
  44. for lo = 1, Longueur do
  45. checkFuel(currentSlot)
  46. turtle.placeDown()
  47. gotoNextSlotIfEmpty() -- This call runs the function above, functions must be placed above where they are used.
  48. if lo ~= Longueur then -- ~= means 'not equal'
  49. turtle.forward()
  50. end
  51.  
  52. end
  53.  
  54. -- retour
  55. turtle.turnRight()
  56. turtle.forward()
  57. turtle.turnRight()
  58.  
  59. for lo = 1, Longueur do
  60.  
  61. turtle.placeDown()
  62. gotoNextSlotIfEmpty() -- This call runs the function above, functions must be placed above where they are used.
  63. if lo ~= Longueur then -- ~= means 'not equal'
  64. turtle.forward()
  65. end
  66.  
  67. end
  68.  
  69.  
  70. if la ~= Largeur/2 then
  71. turtle.turnLeft()
  72. turtle.forward()
  73. turtle.turnLeft()
  74. end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement