Posted 26 October 2015 - 11:50 PM
Recently I developed a code to make a 3x3 hallway at whatever length you want with 3x3 "branches" going as deep as you want; For the most part it runs amazingly. However, when it's suppose to finish the last branch it starts making an additional one, THEN it tries to head to the beginning but can't make it.
Could someone please look over it and help me make it better? Thank you in advance.
I made my code unique in the sense that it needs 3 different enderchest (from EnderStorage mod) one for item dumping, one for fuel, and one for torches
Slot: 1 > enderchest for item dumping only
Slot: 2 > enderchest for fuel only (must have fuel inside)
Slot: 3 > enderchest for torches only (must have torches in it)
Slot: 4 > at least 1 torch (torches have to be in the torches chest in slot 3 for this to work)
Original code
Could someone please look over it and help me make it better? Thank you in advance.
I made my code unique in the sense that it needs 3 different enderchest (from EnderStorage mod) one for item dumping, one for fuel, and one for torches
Slot: 1 > enderchest for item dumping only
Slot: 2 > enderchest for fuel only (must have fuel inside)
Slot: 3 > enderchest for torches only (must have torches in it)
Slot: 4 > at least 1 torch (torches have to be in the torches chest in slot 3 for this to work)
Original code
local tArgs = { ... }
if #tArgs~= 2 then
print(" Usage: stripper <Hallway length> <Tunnel Length>")
return
end
local hallway = tonumber( tArgs[1] )
local mines = tonumber( tArgs[2] )
if hallway < 1 then
print(" Tunnel length must be positive!")
return
end
if mines < 1 then
print(" Number of mines must be positive!")
return
end
local torch = turtle.getItemCount(4)
local hallLength = 0
local minesLength = 0
local torchCounter = 0
--ItemDump must have a secondary enderchest from which items will be pulled from
function itemDump() -- Places down designated Enderchest to get rid of ITEMS mined
if turtle.getItemCount(16) > 0 then
turtle.select(1)
turtle.digDown()
turtle.placeDown()
for slot = 6,16,1 do
turtle.select(slot)
turtle.dropDown()
end
turtle.select(1)
turtle.digDown()
turtle.select(5)
turtle.placeDown()
end
end
function fuel()
if turtle.getFuelLevel() < 10 then
turtle.select(2)
turtle.digDown()
turtle.placeDown()
turtle.select(2)
for f=1,5,1 do
while not suckDown(1) do
print("No FUEL discovered!")
print("Waiting on FUEL!")
end
sleep(0.5)
turtle.refuel()
sleep(0.2)
end
print("Turtle refueled!")
term.clear()
turtle.digDown()
end
end
function placeTorch()
turtle.turnLeft()
while not turtle.forward() do
turtle.dig()
sleep(0.4)
itemDump()
end
fuel()
turtle.turnLeft()
turtle.select(4)
turtle.place()
turtle.turnLeft()
while not turtle.forward() do
turtle.dig()
sleep(0.4)
itemDump()
end
turtle.turnLeft()
torch = turtle.getItemCount()
end
function cTorch()
if torch < 5 then
turtle.select(3)
turtle.digDown()
turtle.placeDown()
turtle.select(4)
for o=1,30,1 do
while not turtle.suckDown(1) do
print("No TORCHES discovered!")
print("Waiting for TORCHES!")
sleep(5)
term.clear()
end
end
print("Torches aquired!")
term.clear()
turtle.select(3)
turtle.digDown()
turtle.select(5)
turtle.placeDown()
cTorch()
else
placeTorch()
end
end
function blockDetection()
while turtle.detect() do
turtle.dig()
itemDump()
sleep(0.5)
end
end
function up()
while not turtle.up() do
turtle.digUp()
itemDump()
sleep(0.5)
end
fuel()
end
function down()
while not turtle.down() do
turtle.digDown()
itemDump()
sleep(0.5)
end
fuel()
end
function forward()
while not turtle.forward() do
turtle.dig()
itemDump()
sleep(0.5)
end
fuel()
end
function nextPhase()
turtle.turnLeft()
turtle.turnLeft()
for i=1,hallLength do
forward()
end
turtle.turnLeft()
turtle.turnLeft()
end
function stripEnd()
turtle.turnLeft()
turtle.turnLeft()
for i=1,minesLength() do
forward()
end
turtle.turnLeft()
end
function destroyColumn()
blockDetection()
up()
blockDetection()
up()
blockDetection()
blockDetection()
down()
blockDetection()
down()
blockDetection()
end
function destroy()
destroyColumn()
turtle.turnLeft()
forward()
turtle.turnRight()
destroyColumn()
turtle.turnLeft()
forward()
turtle.turnRight()
destroyColumn()
turtle.turnRight()
forward()
forward()
turtle.turnLeft()
forward()
end
function home()
turtle.turnLeft()
turtle.turnLeft()
for i=1,hallway,1 do
forward()
end
turtle.turnLeft()
turtle.turnLeft()
end
function nstrip()
turtle.turnLeft()
turtle.turnLeft()
for i=1,mines do
forward()
end
forward()
forward()
turtle.turnLeft()
end
function run()
print("Do you have...")
print("Enderchest in SLOT:1 for item dumping?")
print("Enderchest in SLOT:2 for fuel aquiring?")
print("Enderchest in SLOT:3 for torch getting?")
textutils.slowPrint("Starting in 10 seconds!")
textutils.slowPrint("Hold 'CTRL + T' to abort!")
sleep(10)
for i=1,hallway do
destroy()
torchCounter = torchCounter + 1
if torchCounter = 10 then
cTorch()
torchCounter = 0
end
end
home()
while hallLength < hallway do
for i=1,6 do
forward()
hallLength = hallLength + 1
end
turtle.turnLeft()
forward()
forward()
for h=1,mines do
destroy()
torchCounter = torchCounter + 1
if torchCounter = 9 then
cTorch()
torchCounter = 0
end
end
nstrip()
end
home()
end
———————————————————————————————————————————————————————————————Edited on 30 October 2015 - 07:45 PM