Advertisement
TechManDylan

ChatGPT BuildCylinder v0.2

Jan 6th, 2023
832
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.21 KB | None | 0 0
  1. -- This script will make a turtle build a hollow cylinder with the given radius and height
  2.  
  3. -- Define the function to build the cylinder
  4. function buildCylinder(radius, height)
  5.   -- Set the radius of the cylinder
  6.   local radius = radius
  7.  
  8.   -- Set the height of the cylinder
  9.   local height = height
  10.  
  11.   -- Move the turtle to the starting position
  12.   turtle.up()
  13.   turtle.turnLeft()
  14.   turtle.turnLeft()
  15.   for i=1,radius do
  16.     turtle.forward()
  17.   end
  18.   turtle.turnRight()
  19.  
  20.   -- Define a function to check if the turtle has blocks in its inventory
  21.   function checkInventory()
  22.     for i=1,16 do
  23.       turtle.select(i)
  24.       if turtle.getItemCount() > 0 then
  25.         -- If blocks are found in any slot, return true
  26.         return true
  27.       end
  28.     end
  29.     -- If no blocks are found in any slot, return false
  30.     return false
  31.   end
  32.  
  33.   -- Build the top layer of the cylinder
  34.   for i=1,radius*2 do
  35.     -- Check if the turtle has blocks in its inventory before trying to place a block
  36.     if checkInventory() then
  37.       turtle.placeDown()
  38.     else
  39.       -- If the turtle is out of blocks, spin in a circle and print a message until blocks are added
  40.       while not checkInventory() do
  41.         turtle.turnRight()
  42.         print("Need more blocks")
  43.         sleep(5)
  44.       end
  45.     end
  46.     turtle.forward()
  47.   end
  48.   turtle.turnRight()
  49.   turtle.forward()
  50.   turtle.turnRight()
  51.  
  52.   -- Build the sides of the cylinder
  53.   for j=2,height do
  54.     for i=1,radius*2+1 do
  55.       -- Check if the turtle has blocks in its inventory before trying to place a block
  56.       if checkInventory() then
  57.         turtle.placeDown()
  58.       else
  59.         -- If the turtle is out of blocks, spin in a circle and print a message until blocks are added
  60.         while not checkInventory() do
  61.           turtle.turnRight()
  62.           print("Need more blocks")
  63.           sleep(5)
  64.         end
  65.       end
  66.       turtle.forward()
  67.     end
  68.     turtle.turnRight()
  69.     turtle.forward()
  70.     turtle.turnRight()
  71.   end
  72.  
  73.   -- Return the turtle to the starting position
  74.   turtle.turnRight()
  75.   for i=1,radius+1 do
  76.     turtle.forward()
  77.   end
  78.   turtle.turnLeft()
  79. end
  80.  
  81. -- Test the function by building a cylinder with radius 5 and height 10
  82. buildCylinder(5, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement