View difference between Paste ID: bRpbc2BU and nrykBcBw
SHOW: | | - or go back to the newest paste.
1
--CurrentLuaProgram.lua
2
print("Hello World")
3
--TurtleTower
4
5
--Check arguments for correct formatting
6
local args = { ... }
7
if #args ~= 1 then      --Check if it's not exactly 3 arguments.
8
    shell.run("clear")
9
    print("Invalid number of arguments")
10-
    if tonumber(args[i]) < 2 then
10+
11
    do return end
12
end
13-
        print("All measurements must be numbers greater than 1")
13+
14
    if tonumber(args[i]) < 5 or tonumber(args[i]) > 9 then
15
        shell.run("clear")
16
        print("Invalid arguments")
17
        print("All measurements must be numbers greater than 5 and less than 9")
18
        do return end
19
    end
20-
length = tonumber(args[1])  --length of tunnel
20+
21-
slotnum = 1
21+
22
 
23-
    if turtle.getItemCount(slotnum) < 1 then
23+
24-
        slotnum = slotnum + 1
24+
length = tonumber(args[1])  --length of square
25-
        turtle.select(slotnum)
25+
26
--The position of each of the blocks of interest
27
-- these blocks are used for different parts of the tower.
28
wallslot = 1
29
floorslot = 4
30-
for i = 1, length do
30+
roofslot = 5
31
torchslot = 6
32-
    -- Add Some Flooring
32+
ladderslot = 7
33
glassslot = 8
34-
    turtle.placeDown()
34+
roofslot = 9
35
36-
    turtle.turnLeft()
36+
37-
    turtle.dig()
37+
    if turtle.getItemCount(wallslot) < 1 then
38-
    turtle.forward()
38+
        slotnum = wallslot + 1
39
        turtle.select(wallslot)
40-
    -- Dig Most of the Tunnel
40+
41-
    turtle.placeDown()
41+
42-
    turtle.digUp()
42+
43-
    turtle.up()
43+
44-
    turtle.digUp()
44+
45-
    turtle.up()
45+
--Finish location (at H)
46-
    turtle.turnRight()
46+
-- [ ][w][w][w][ ]
47-
    turtle.turnRight()
47+
-- [w][ ][ ][ ][w]
48-
    turtle.dig()
48+
-- [d][ ][ ][ ][w]
49-
    turtle.forward()
49+
-- [H][ ][ ][ ][w]
50-
    turtle.digDown()
50+
-- [ ][w][w][w][ ]
51-
    turtle.down()
51+
-- This is where the bot should be after each function
52-
    turtle.dig()
52+
-- (top down view) facing up
53-
    turtle.forward()
53+
54-
    turtle.digUp()
54+
55-
    turtle.digDown()
55+
56-
    turtle.down()
56+
-- Create the walls of the tower.
57
function walls (height)
58-
    turtle.placeDown()
58+
	for i = 1, height do
59-
    turtle.back()
59+
		if not turtle.detectUp() then
60-
    turtle.turnLeft()
60+
			turtle.up()
61-
    turtle.dig()
61+
		end
62-
    turtle.forward()
62+
		for j = 1, 4 do
63
			for k = 1, 3 do
64-
end
64+
				if not turtle.detectDown() then
65
					checkSlots()
66
					turtle.placeDown()
67
				end
68
				turtle.forward()
69
			end
70
			turtle.turnRight()
71
			turtle.forward()
72
		end
73
	end
74
end
75
76
-- Door and windows.
77
function openings(height)
78
	--get back to floor level
79
	turtle.forward()
80
	turtle.turnLeft()
81
	turtle.back()
82
	for i = 1, length do
83
		turtle.down()
84
	end
85
	
86
	currentHeight = 1
87
	
88
	turtle.dig()
89
	turtle.up()
90
	turtle.dig()
91
	currentHeight = currentHeight + 1
92
    
93
	while currentHeight < height - 3 do
94
        for i = 1, 4 do
95
            if i == 4 and currentHeight == 2 then
96
                continue
97
            end
98
            turtle.back()
99
            turtle.turnRight()
100
            turtle.forward()
101
            turtle.dig()
102
            turtle.up()
103
            turtle.dig()
104
            turtle.down()
105
        end
106
        turtle.up()
107
        turtle.up()
108
        turtle.up()
109
        turtle.up()
110
        currentHeight = currentHeight + 4
111
    end
112
end
113
114
walls(length)
115
openings(length)