View difference between Paste ID: R143117y and CnwTLd4R
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
    print("turtletower [height]")
11
    do return end
12
end
13
for i = 1, 1 do            --Step through each argument and make sure it is a number greater than 1.
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
end
21
--------------------------------------------------
22
 
23
--commandline arguments [height]
24
length = tonumber(args[1])  --length of square
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
roofslot = 5
31
torchslot = 6
32
ladderslot = 7
33
glassslot = 8
34
roofslot = 9
35
36
function checkSlots()
37
    if turtle.getItemCount(wallslot) < 1 then
38
        slotnum = wallslot + 1
39
        turtle.select(wallslot)
40
    end
41
    return
42
end
43
--------------------------------------------------
44
45
--Finish location (at H)
46
-- [ ][w][w][w][ ]
47
-- [w][ ][ ][ ][w]
48
-- [d][ ][ ][ ][w]
49
-- [H][ ][ ][ ][w]
50
-- [ ][w][w][w][ ]
51
-- This is where the bot should be after each function
52
-- (top down view) facing up
53
54
55
56
-- Create the walls of the tower.
57
function walls (height)
58
	for i = 1, height do
59
		if not turtle.detectUp() then
60
			turtle.up()
61
		end
62
		for j = 1, 4 do
63
			for k = 1, 3 do
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
            print("Door Created")
97
            else
98
            turtle.back()
99
            turtle.turnRight()
100
            turtle.forward()
101
            turtle.dig()
102
            turtle.up()
103
            turtle.dig()
104
            turtle.down()
105
            end
106
        end
107
        turtle.up()
108
        turtle.up()
109
        turtle.up()
110
        turtle.up()
111
        currentHeight = currentHeight + 4
112
    end
113
end
114
115
walls(length)
116
openings(length)
117
118
-- turtle.turnRight()
119
-- turtle.turnRight()
120
-- turtle.dig()
121
-- turtle.up()
122
-- turtle.dig()
123
-- turtle.down()
124
-- turtle.turnRight()
125
-- turtle.forward()
126
-- turtle.turnRight()
127
-- for i = 1, length do
128
    -- turtle.forward()
129
    -- if turtle.getItemCount(slotnum) < 1 then
130
        -- slotnum = slotnum + 1
131
        -- turtle.select(slotnum)
132
    -- end
133
	-- turtle.placeDown()
134
    -- turtle.up()
135
    -- turtle.forward()
136
    -- if turtle.getItemCount(slotnum) < 1 then
137
        -- slotnum = slotnum + 1
138
        -- turtle.select(slotnum)
139
    -- end
140
    -- turtle.placeDown()
141
    -- turtle.turnRight()
142
-- end