Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This script will make a turtle build a hollow cylinder with the given radius and height
- -- Define the function to build the cylinder
- function buildCylinder(radius, height)
- -- Set the radius of the cylinder
- local radius = radius
- -- Set the height of the cylinder
- local height = height
- -- Move the turtle to the starting position
- turtle.up()
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,radius do
- turtle.forward()
- end
- turtle.turnRight()
- -- Define a function to check if the turtle has blocks in its inventory
- function checkInventory()
- for i=1,16 do
- turtle.select(i)
- if turtle.getItemCount() > 0 then
- -- If blocks are found in any slot, return true
- return true
- end
- end
- -- If no blocks are found in any slot, return false
- return false
- end
- -- Build the top layer of the cylinder
- for i=1,radius*2 do
- -- Check if the turtle has blocks in its inventory before trying to place a block
- if checkInventory() then
- turtle.placeDown()
- else
- -- If the turtle is out of blocks, spin in a circle and print a message until blocks are added
- while not checkInventory() do
- turtle.turnRight()
- print("Need more blocks")
- sleep(5)
- end
- end
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- -- Build the sides of the cylinder
- for j=2,height do
- for i=1,radius*2+1 do
- -- Check if the turtle has blocks in its inventory before trying to place a block
- if checkInventory() then
- turtle.placeDown()
- else
- -- If the turtle is out of blocks, spin in a circle and print a message until blocks are added
- while not checkInventory() do
- turtle.turnRight()
- print("Need more blocks")
- sleep(5)
- end
- end
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- turtle.turnRight()
- end
- -- Return the turtle to the starting position
- turtle.turnRight()
- for i=1,radius+1 do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- -- Test the function by building a cylinder with radius 5 and height 10
- buildCylinder(5, 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement