Posted 20 February 2020 - 06:28 PM
So I am trying to make a script that builds four walls with whatever building blocks are provided. The problem I have with the script right now is that when the turtle's inventory runs out of building blocks, the turtle keeps moving forward along the path. How can I make the turtle stop moving when it runs out of building blocks?
This is my code:
This is my code:
write("How wide should the room be?")
local x = tonumber(read())
write("How long should the room be?")
local y = tonumber(read())
write("How tall should the room be?")
local z = tonumber(read())
write("Provide fuel and whatever building block you want to use and press enter to continue")
read()
local totalBlocks = ((x*2) + (y*2))*z
local minedBlocks = 0
function go()
if not refuel() then
return
end
if not forward() then
return
end
if not place() then
return
end
minedBlocks = minedBlocks +1
percentComplete = minedBlocks / totalBlocks * 100
if(percentComplete % 5 == 0) then
print(percentComplete.."% Complete")
end
end
function forward()
if not turtle.forward() then
write("Something is in the way!")
return false
end
return true
end
function down()
if not turlte.down() then
write("Something is in the way!")
return false
end
return true
end
function place()
slot = 0
while turtle.placeUp() == false do
slot = slot + 1
if slot == 17 then
print("Waiting for more building blocks...")
return false
end
turtle.select(slot)
end
return true
end
function refuel()
while turtle.getFuelLevel() == 0 do
slot = 0
while(turtle.refuel(1) == false) do
slot = slot + 1
if slot == 17 then
print("Waiting for more fuel...")
return false
end
turtle.select(slot)
end
end
return true
end
write("0% Complete...")
turtle.down()
for h=0,z,1 do
for i=0,1,1 do
for w=0,y,1 do
go()
end
turtle.turnRight()
for l=0,x,1 do
go()
end
turtle.turnRight()
end
turtle.down()
end
print("Construction complete.")