SHOW:
|
|
- or go back to the newest paste.
| 1 | local tArgs = { ... }
| |
| 2 | ||
| 3 | if #tArgs ~= 2 then | |
| 4 | print( "Usage: stairs <depth>, <length>" ) | |
| 5 | return | |
| 6 | end | |
| 7 | ||
| 8 | local depth = tonumber( tArgs[1] ) | |
| 9 | if depth < 1 then | |
| 10 | print( "stair depth must be positive" ) | |
| 11 | return | |
| 12 | end | |
| 13 | ||
| 14 | local length = tonumber( tArgs[2] ) | |
| 15 | if length < 1 then | |
| 16 | print( "stair length must be positive" ) | |
| 17 | return | |
| 18 | end | |
| 19 | ||
| 20 | - | local function digForward() |
| 20 | + | |
| 21 | - | while (turtle.detect()) do |
| 21 | + | |
| 22 | - | turtle.dig() |
| 22 | + | |
| 23 | - | sleep(0.2) |
| 23 | + | |
| 24 | end | |
| 25 | ||
| 26 | local fuelLevel = turtle.getFuelLevel() | |
| 27 | - | local function digUp() |
| 27 | + | |
| 28 | - | while (turtle.detectUp()) do |
| 28 | + | |
| 29 | return | |
| 30 | - | sleep(0.2) |
| 30 | + | |
| 31 | ||
| 32 | print("stairs "..depth.." x "..length)
| |
| 33 | ||
| 34 | local curDepth = 0 | |
| 35 | turtle.select(1) | |
| 36 | ||
| 37 | ||
| 38 | while (curDepth < depth) do | |
| 39 | for i=1,length do | |
| 40 | ||
| 41 | turtle.digUp() | |
| 42 | turtle.up() | |
| 43 | turtle.digUp() | |
| 44 | ||
| 45 | turtle.dig() | |
| 46 | turtle.forward() | |
| 47 | ||
| 48 | if (curDepth == depth) then | |
| 49 | return | |
| 50 | end | |
| 51 | ||
| 52 | curDepth = curDepth + 1 | |
| 53 | - | digForward() |
| 53 | + | |
| 54 | turtle.turnRight() | |
| 55 | - | turtle.digDown() |
| 55 | + | |
| 56 | - | digUp() |
| 56 | + | |
| 57 | turtle.turnRight() | |
| 58 | - | if (not turtle.detectDown()) then |
| 58 | + | |
| 59 | - | turtle.placeDown() |
| 59 | + | |
| 60 | - | else |
| 60 | + | |
| 61 | - | if (not turtle.compareDown()) then |
| 61 | + | |
| 62 | - | turtle.digDown() |
| 62 | + | |
| 63 | - | turtle.placeDown() |
| 63 | + | |
| 64 | - | end |
| 64 | + | |
| 65 | ||
| 66 | curDepth = curDepth + 1 | |
| 67 | if (curDepth == depth) then | |
| 68 | return | |
| 69 | end | |
| 70 | end | |
| 71 | turtle.turnLeft() | |
| 72 | end |