Posted 24 December 2012 - 01:53 PM
I am trying to run this code which makes a platform, sometimes when I run it, it automatically goes to "Error: block in the way", but also sometimes it does not, the first time I ever ran it, it ran flawlessly, but I tried a second time and it failed; it also sometimes just stops and gives me the error "Error: block in the way" when there is not a block in the way.
After it gives me the "Error: block in the way" I goto the lua interpreter and type turtle.forward() but it comes up with "false" when I do it even when it should not.
I have the correct slots filled too.
After it gives me the "Error: block in the way" I goto the lua interpreter and type turtle.forward() but it comes up with "false" when I do it even when it should not.
I have the correct slots filled too.
local blocks = turtle.getItemCount(2)
for slot=3,16 do
if turtle.compareTo(2) then
blocks = blocks + turtle.getItemCount(slot)
end
end
size = math.floor(math.sqrt(blocks))
sizeStr = tostring(size)
print("Making a " .. sizeStr .. "x" .. sizeStr .. " platform")
function prevBlockSlot(curSlot)
for slot=curSlot,2,-1 do
turtle.select(slot)
if turtle.compareTo(2) then
return slot
end
end
end
function forward(curSlot)
if turtle.getFuelLevel() < 1 then
select(1)
turtle.refuel(1)
turtle.select(curSlot)
end
for i=1,10 do
if turtle.detect() then
turtle.dig()
end
if turtle.forward() then
return true
end
end
return nil
end
function placeDown(curSlot)
if not turtle.compareTo(2) then
curSlot = prevBlockSlot(curSlot)
end
turtle.placeDown()
return curSlot
end
local curSlot = prevBlockSlot(16)
for row=1,size do
for i=1,size-1 do
curSlot = placeDown(curSlot)
if not forward(curSlot) then
print("Error: block in the way")
return
end
end
curSlot = placeDown(curSlot)
if row%2 == 1 then
turtle.turnRight()
if not forward(curSlot) then
print("Error: block in the way")
return
end
turtle.turnRight()
else
turtle.turnLeft()
if not forward(curSlot) then
print("Error: block in the way")
return
end
turtle.turnLeft()
end
end