SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- Programmed: 17 May 2014 |
| 1 | + | |
| 2 | - | -- by Skyler James |
| 2 | + | if #tArgs ~= 2 then |
| 3 | - | -- |
| 3 | + | print( "Usage: bridge <length> <direction of landmark (L, R, B)>" ) |
| 4 | - | -- Builds a bridge <length> |
| 4 | + | |
| 5 | - | -- blocks long, 1 block wide |
| 5 | + | |
| 6 | - | -- |
| 6 | + | |
| 7 | - | -- The blocks to be used in |
| 7 | + | |
| 8 | - | -- the bridge MUST be placed |
| 8 | + | |
| 9 | - | -- in slot 9. There is error |
| 9 | + | |
| 10 | - | -- checking to ensure this. |
| 10 | + | |
| 11 | - | -- |
| 11 | + | |
| 12 | - | -- Turtle will NOT break any |
| 12 | + | |
| 13 | - | -- blocks in its way |
| 13 | + | |
| 14 | -- Check that there are <length> | |
| 15 | -- blocks provided in slot 9 | |
| 16 | - | if #tArgs ~= 1 then |
| 16 | + | --local numblocks = turtle.getItemCount(9) |
| 17 | - | print( "Usage: bridge <length>" ) |
| 17 | + | --if numblocks < length then |
| 18 | -- print("Please place at least "..length.." building blocks in slot 9")
| |
| 19 | -- return | |
| 20 | --end | |
| 21 | ||
| 22 | -- Place a block underneath | |
| 23 | -- the turtle to build bridge | |
| 24 | function putblockdown() | |
| 25 | if not (turtle.detectDown()) then | |
| 26 | turtle.select(9) | |
| 27 | turtle.placeDown() | |
| 28 | end | |
| 29 | end | |
| 30 | - | local numblocks = turtle.getItemCount(9) |
| 30 | + | |
| 31 | - | if numblocks < length |
| 31 | + | -- Place Landmark in front |
| 32 | - | print("Please place at least "..length.." building blocks in slot 9")
|
| 32 | + | function placelm() |
| 33 | if tArgs[2] == "R" then | |
| 34 | if not (turtle.detect()) then | |
| 35 | turtle.turnRight() | |
| 36 | turtle.forward() | |
| 37 | turtle.select(9) | |
| 38 | turtle.placeDown() | |
| 39 | turtle.back() | |
| 40 | turtle.select(10) | |
| 41 | turtle.place() | |
| 42 | turtle.turnLeft() | |
| 43 | end | |
| 44 | end | |
| 45 | if tArgs[2] == "L" then | |
| 46 | if not (turtle.detect()) then | |
| 47 | turtle.turnLeft() | |
| 48 | turtle.forward() | |
| 49 | - | for i,length,1 do |
| 49 | + | turtle.select(9) |
| 50 | - | if (turtle.detect()) then |
| 50 | + | turtle.placeDown() |
| 51 | - | break |
| 51 | + | turtle.back() |
| 52 | - | else |
| 52 | + | turtle.select(10) |
| 53 | - | putblockdown() |
| 53 | + | turtle.place() |
| 54 | - | turtle.forward() |
| 54 | + | turtle.turnRight() |
| 55 | end | |
| 56 | end | |
| 57 | if tArgs[2] == "B" then | |
| 58 | if not (turtle.detect()) then | |
| 59 | turtle.turnRight() | |
| 60 | turtle.forward() | |
| 61 | turtle.select(9) | |
| 62 | turtle.placeDown() | |
| 63 | turtle.back() | |
| 64 | turtle.select(10) | |
| 65 | turtle.place() | |
| 66 | turtle.turnLeft() | |
| 67 | turtle.turnLeft() | |
| 68 | turtle.forward() | |
| 69 | turtle.select(9) | |
| 70 | turtle.placeDown() | |
| 71 | turtle.back() | |
| 72 | turtle.select(10) | |
| 73 | turtle.place() | |
| 74 | turtle.turnRight() | |
| 75 | end | |
| 76 | end | |
| 77 | end | |
| 78 | ||
| 79 | function backhome() | |
| 80 | x = length | |
| 81 | while x > 0 do | |
| 82 | -- putblockdown() | |
| 83 | turtle.back() | |
| 84 | x = x - 1 | |
| 85 | end | |
| 86 | end | |
| 87 | -- Move forward <length> times | |
| 88 | -- and build a bridge with | |
| 89 | -- blocks provided in slot 9 | |
| 90 | local i = 0 | |
| 91 | while i < length do | |
| 92 | -- putblockdown() | |
| 93 | turtle.forward() | |
| 94 | i = i + 1 | |
| 95 | end | |
| 96 | ||
| 97 | placelm() | |
| 98 | backhome() | |
| 99 | ||
| 100 | -- That's all, folks! | |
| 101 | print("Built a bridge "..i.." blocks long")
| |
| 102 | return |