icdb icon

[computercraft] lumber

icdb | PRO | 02/15/15 01:00:46 PM UTC | 0 ⭐ | 595 👁️ | Never ⏰ | []
Lua |

1.55 KB

|

None

|

0 👍

/

0 👎

local tArgs = { ... }
if #tArgs == 1 then
    wide = tArgs[1]
    mode = "0"
    if wide == "1" or wide == "2" then
        print("wide = ",wide,"x",wide)
        print("mode = ",mode)
    else
    error()
    end
elseif #tArgs == 2 then
    wide = tArgs[1]
    mode = tArgs[2]
    if (wide == "1" or wide == "2") and (mode == "0" or mode == "1") then
        print("wide = ",wide,"x",wide)
        print("mode = ",mode)
    else
        error()
        return
    end
else
    wide="1"
    mode="0"
    print("wide = ",wide,"x",wide)
    print("mode = ",mode)
end
 
function error()
    print("Usage:")
    print("lumber <wide> <mode>")
    print("wide = 1 (1x1) or 2 (2x2)")
    print("if wide is empty: wide = 1")
    print("mode = 0 or 1")
    print("if mode is empty: mode = 0")
    print("mode only works if wide = 1")
end
 
if wide == "1" then
    turtle.dig()
    turtle.forward()
    z=0
    repeat
      turtle.digUp()
      turtle.up()
      if mode == "1" then
        for i=1,4 do
            turtle.dig()
            turtle.turnRight()
        end
      end
      z=z+1
    until turtle.detectUp()==false
 
    for i=1,z do
      turtle.digDown()
      turtle.down()
    end
 
    turtle.back()   
 
elseif wide == "2" then
 
    turtle.dig()
    turtle.forward()
    z=0
      turtle.dig()
    repeat
      turtle.digUp()
      turtle.up()
      turtle.dig()
      z=z+1
    until turtle.detectUp()==false
     
    turtle.turnRight()
    turtle.dig()
    turtle.forward()
    turtle.turnLeft()
     
    turtle.dig()
     
    for i=1,z do
      turtle.digDown()
      turtle.down()
      turtle.dig()
    end
     
    turtle.turnLeft()
    turtle.forward()
    turtle.turnLeft()
    turtle.forward()
    turtle.turnRight()
    turtle.turnRight()
 
end

Comments