moverperfect

Pyramid

Oct 5th, 2012
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.88 KB | None | 0 0
  1. -- Pyramid script
  2. -- Needs murtle to work
  3.  
  4. local slot = 1
  5. turtle.select(1)
  6. local p = 0
  7.  
  8. -- Functionality to ensure that correct slot is selected, is not currently used, will be implemented later
  9. -- function add()
  10. --  p=p+1
  11. --  if p == "64" then
  12. --      turtle.select(slot+1)
  13. --      slot = slot + 1
  14. --  end
  15. --end
  16.  
  17. -- Check that user has entered the correct parameters
  18. local arg = {...}
  19. if arg == nil then
  20.     print("Usage: pyramid <radius>")
  21.     return 2
  22. end
  23.  
  24. -- Saving a variable to the value that the user entered
  25. radius = tonumber (arg[1])
  26.  
  27. -- Checking that murtle hsa been installed and is loaded
  28. path=shell.resolveProgram("murtle")
  29. if path==nil or not os.loadAPI(path) then
  30.   print("Cant load library: murtle")
  31.   return 1
  32. end
  33.  
  34.  
  35. -- Travelling to the top left corner of the pyramid to start the building
  36. turtle.select(1)
  37. murtle.up()
  38. -- Placing a block in the middle as a reference(You can delete if you need)
  39. murtle.placedown()
  40. add()
  41. murtle.fwd(radius-1)
  42. murtle.left()
  43. murtle.fwd(radius-1)
  44. murtle.left()
  45.  
  46. -- Setting a length vaule of the pyramid for future reference
  47. local diameter = 2*radius-2
  48.  
  49. -- Starting the for loops, first one repeates the levels going up
  50. for x=1,radius - 1 do
  51.  
  52.     -- Second for loops does the four sides of the pyramid
  53.     for y=1,4 do
  54.         -- Radi determines how long the length of each level will be
  55.         radi = ((0-x)*2)+diameter+2
  56.         -- Third loop deals with the forward and placing the length of the side
  57.         for z=1,radi do
  58.             murtle.fwd()
  59.             murtle.placedown()
  60.             add()
  61.         end
  62.         -- Turning left to prepare for the next side
  63.         murtle.left()
  64.     end
  65.     -- After finishing all four sides of the level, it goes up one more level and gets ready to repeat
  66.     murtle.up()
  67.     murtle.left()
  68.     murtle.fwd()
  69.     murtle.right()
  70.     murtle.fwd()
  71. end
  72.  
  73. -- The turtle actually finishes without placing the top block so we do this at the end after the loops
  74. murtle.placedown()
  75. add()
Advertisement
Add Comment
Please, Sign In to add comment