Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CurrentLuaProgram.lua
- print("Hello World")
- --TurtleTower
- --Check arguments for correct formatting
- local args = { ... }
- if #args ~= 1 then --Check if it's not exactly 3 arguments.
- shell.run("clear")
- print("Invalid number of arguments")
- print("turtletower [height]")
- do return end
- end
- for i = 1, 1 do --Step through each argument and make sure it is a number greater than 1.
- if tonumber(args[i]) < 5 or tonumber(args[i]) > 9 then
- shell.run("clear")
- print("Invalid arguments")
- print("All measurements must be numbers greater than 5 and less than 9")
- do return end
- end
- end
- --------------------------------------------------
- --commandline arguments [height]
- length = tonumber(args[1]) --length of square
- --The position of each of the blocks of interest
- -- these blocks are used for different parts of the tower.
- wallslot = 1
- floorslot = 4
- roofslot = 5
- torchslot = 6
- ladderslot = 7
- glassslot = 8
- roofslot = 9
- function checkSlots()
- if turtle.getItemCount(wallslot) < 1 then
- slotnum = wallslot + 1
- turtle.select(wallslot)
- end
- return
- end
- --------------------------------------------------
- --Finish location (at H)
- -- [ ][w][w][w][ ]
- -- [w][ ][ ][ ][w]
- -- [d][ ][ ][ ][w]
- -- [H][ ][ ][ ][w]
- -- [ ][w][w][w][ ]
- -- This is where the bot should be after each function
- -- (top down view) facing up
- -- Create the walls of the tower.
- function walls (height)
- for i = 1, height do
- if not turtle.detectUp() then
- turtle.up()
- end
- for j = 1, 4 do
- for k = 1, 3 do
- if not turtle.detectDown() then
- checkSlots()
- turtle.placeDown()
- end
- turtle.forward()
- end
- turtle.turnRight()
- turtle.forward()
- end
- end
- end
- -- Door and windows.
- function openings(height)
- --get back to floor level
- turtle.forward()
- turtle.turnLeft()
- turtle.back()
- for i = 1, length do
- turtle.down()
- end
- currentHeight = 1
- turtle.dig()
- turtle.up()
- turtle.dig()
- currentHeight = currentHeight + 1
- while currentHeight < height - 3 do
- for i = 1, 4 do
- if i == 4 and currentHeight == 2 then
- print("Door Created")
- else
- turtle.back()
- turtle.turnRight()
- turtle.forward()
- turtle.dig()
- turtle.up()
- turtle.dig()
- turtle.down()
- end
- end
- turtle.up()
- turtle.up()
- turtle.up()
- turtle.up()
- currentHeight = currentHeight + 4
- end
- end
- walls(length)
- openings(length)
- -- turtle.turnRight()
- -- turtle.turnRight()
- -- turtle.dig()
- -- turtle.up()
- -- turtle.dig()
- -- turtle.down()
- -- turtle.turnRight()
- -- turtle.forward()
- -- turtle.turnRight()
- -- for i = 1, length do
- -- turtle.forward()
- -- if turtle.getItemCount(slotnum) < 1 then
- -- slotnum = slotnum + 1
- -- turtle.select(slotnum)
- -- end
- -- turtle.placeDown()
- -- turtle.up()
- -- turtle.forward()
- -- if turtle.getItemCount(slotnum) < 1 then
- -- slotnum = slotnum + 1
- -- turtle.select(slotnum)
- -- end
- -- turtle.placeDown()
- -- turtle.turnRight()
- -- end
Advertisement
Add Comment
Please, Sign In to add comment