diff --git a/digroom.lua b/digroom.lua index 981a4cf..bfa0cd3 100644 --- a/digroom.lua +++ b/digroom.lua @@ -1,14 +1,18 @@ --- local coordinates! local tArgs = { ... } -local x = tArgs[1] -local y = tArgs[2] -local z = tArgs[3] -local fuel = 16 +if table.maxn(tArgs) ~= 3 then + print("This program digs a room in front of the turtle to the right.") + print("Arguments: width, length, height.") + return +end +local width = tArgs[1] +local length = tArgs[2] +local height = tArgs[3] local up = true local fw = false +print("Digging room with", width, "width,", length, "length and", height, "height.") local function digUp() - for i = 2, z do + for i = 2, height do while not turtle.up() do turtle.digUp() end @@ -16,7 +20,7 @@ local function digUp() end local function digDown() - for i = 2, z do + for i = 2, height do while not turtle.down() do turtle.digDown() end @@ -40,25 +44,26 @@ end local function turn() if fw then - turtle.turnRight() - else turtle.turnLeft() + else + turtle.turnRight() end end local function refuel() - if turtle.getFuelLevel() <= 4 * z then + if turtle.getFuelLevel() <= 4 * height then if not turtle.refuel() then print("No fuel!") end end end -for i = 1, x do +refuel() +for i = 1, width do digFw() turn() fw = not fw - for j = 2, y do + for j = 2, length do digVertical() digFw() refuel()