SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- 'flat' for turtles |
| 1 | + | -- Turtle will move forward and to the right. |
| 2 | - | -- Made by ryanv09 |
| 2 | + | -- Turtle will build below itself. |
| 3 | ||
| 4 | - | -- Place the turtle at southwest corner of desired surface |
| 4 | + | |
| 5 | ||
| 6 | length = tonumber(arg[1]) | |
| 7 | width = tonumber(arg[2]) | |
| 8 | - | length = arg[1] |
| 8 | + | |
| 9 | - | width = arg[2] |
| 9 | + | currentSlot = 1 |
| 10 | processMore = true | |
| 11 | ||
| 12 | - | -- Change this value to reflect how many total slots the turtle has |
| 12 | + | |
| 13 | - | -- This is the slot that is checked for empty() |
| 13 | + | |
| 14 | - | slots = 16 |
| 14 | + | print ("Usage: Program <length> <width>")
|
| 15 | print ("Length = Blocks forward.")
| |
| 16 | print ("Width = Blocks to the right.")
| |
| 17 | return | |
| 18 | end | |
| 19 | - | print ("Usage: flat <length> <width>")
|
| 19 | + | |
| 20 | - | return |
| 20 | + | -- Checks if the turtle slot is empty |
| 21 | -- Going from slot to 16 wrapping (1 - 16) | |
| 22 | function slotEmpty() | |
| 23 | for i=0,16,1 do | |
| 24 | - | -- Checks if the turtle is empty |
| 24 | + | newSlot = ((currentSlot + i) % 16) + 1 |
| 25 | - | -- If empty, pauses turtle until last slot has resources |
| 25 | + | if (turtle.getItemCount(newSlot) ~= 0) then |
| 26 | - | function empty() |
| 26 | + | currentSlot = newSlot |
| 27 | - | if (turtle.getItemCount(slots) == 0) then |
| 27 | + | turtle.select(newSlot) |
| 28 | - | print(string.format("I am empty. Please load more materials in slot %d to continue.", slots))
|
| 28 | + | print("\nFound a block at ".. newSlot .. " carry on")
|
| 29 | - | while (turtle.getItemCount(slots) == 0) do |
| 29 | + | return true |
| 30 | - | sleep(1) |
| 30 | + | end |
| 31 | - | end |
| 31 | + | end |
| 32 | - | end |
| 32 | + | print("\nI've run out of blocks, I will wait for more.")
|
| 33 | return false | |
| 34 | end | |
| 35 | ||
| 36 | for i=0,(width - 1),1 do | |
| 37 | for j=1,(length - 1),1 do | |
| 38 | - | for j=1,(length - 1),1 do |
| 38 | + | processMore = slotEmpty() |
| 39 | - | empty() |
| 39 | + | if processMore then |
| 40 | - | turtle.forward() |
| 40 | + | turtle.forward() |
| 41 | - | turtle.placeDown() |
| 41 | + | turtle.placeDown() |
| 42 | - | end |
| 42 | + | end |
| 43 | end | |
| 44 | - | |
| 44 | + | |
| 45 | - | if (i % 2 == 0) then |
| 45 | + | if not processMore then |
| 46 | - | |
| 46 | + | print("I have run out of blocks to place, I will wait for more.")
|
| 47 | - | if (i ~= width - 1) then |
| 47 | + | break |
| 48 | - | turtle.turnRight() |
| 48 | + | end |
| 49 | - | turtle.forward() |
| 49 | + | |
| 50 | - | turtle.turnRight() |
| 50 | + | if (i % 2 == 0) then |
| 51 | - | empty() |
| 51 | + | if (i ~= width - 1) then |
| 52 | - | turtle.placeDown() |
| 52 | + | turtle.turnRight() |
| 53 | - | end |
| 53 | + | turtle.forward() |
| 54 | - | else |
| 54 | + | turtle.turnRight() |
| 55 | - | if (i ~= width - 1) then |
| 55 | + | end |
| 56 | - | turtle.turnLeft() |
| 56 | + | else |
| 57 | - | turtle.forward() |
| 57 | + | if (i ~= width - 1) then |
| 58 | - | turtle.turnLeft() |
| 58 | + | turtle.turnLeft() |
| 59 | - | empty() |
| 59 | + | turtle.forward() |
| 60 | - | turtle.placeDown() |
| 60 | + | turtle.turnLeft() |
| 61 | - | end |
| 61 | + | end |
| 62 | - | end |
| 62 | + | end |
| 63 | ||
| 64 | - | if (j ~= length - 1) then |
| 64 | + | -- See if we have an item in any slot, if we do, then place it |
| 65 | - | empty() |
| 65 | + | -- if we don't have any items, then we break out of the loop, cause we're done |
| 66 | - | turtle.placeDown() |
| 66 | + | processMore = slotEmpty() |
| 67 | - | end |
| 67 | + | if processMore then |
| 68 | turtle.placeDown() | |
| 69 | else | |
| 70 | - | print("\nSurface complete.") |
| 70 | + | break |
| 71 | end | |
| 72 | end | |
| 73 | ||
| 74 | print("\nMy programming indicates that the floor is completed.") |