Posted 24 February 2014 - 08:09 AM
so im writing a program with the intention of having a turtle dig a stair well down or up (user specifies) and then how many down or up to actually go . i have certain failure prevention functions to avoid the turtle either running out of inventory space, or hitting a gravity block like gravel. those functions are contained within the digcheck, digcheckup, inventory up, and go back commands. now my problem is that if it dosn't have a chest and decides to run the goback function, instead it simply digs a 3x1xinfinity tunnel in whatever direction the staircase was headed. for example, it fills up when you set it to make a staircase down, now it has a staircase leading to a pit to bedrock, or if you said for it to go up, its stuck at the highest point in the world by the end. at this point im absolutely baffled as to why that is. if someone could take a look. what the go back command SHOULD do is, send the turtle back as many steps as its currently gone forward, the variable curr, simply adds 1 every time the stairdown or up commands loop, that way the go back command knows how far into the task the turtle is and can go back the appropriate amount of spaces. however its simply not doing that.
at this point im so stuck, i started lua friday of last week so im obviously missing something important here. a helpful response will be so so appreciated. thanks again to anybody willing to take a look. also please, try it out for yourselves. see what results you get, its very odd D:
edit- wrong code was put in (earlier version) -most recent version input (same problems)
tArgs={...}
if #tArgs<2 then
print("Stairs <number of stairs> <up or down>")
end
x = tArgs[1]
ud = tArgs[2]
function goBack()
turtle.turnRight()
turtle.turnRight()
if ud == down then
for i = 1, curr do
print(curr)
turtle.forward()
turtle.up()
end
elseif ud == up then
print(curr)
for i = 1, curr do
turtle.down()
turtle.forward()
end
end
turtle.forward()
end
function digcheck()
local a = turtle.detect()
while a == true do
turtle.dig()
a = turtle.detect()
end
end
function digCheckUp()
local b = turtle.detectUp()
while b == true do
turtle.digUp()
b = turtle.detectUp()
end
end
function stairDown(x)
curr = 0
for i = 1,x do
curr = curr + 1
digcheck()
turtle.digDown()
turtle.down()
digcheck()
turtle.forward()
inventoryOk()
end
turtle.turnRight()
turtle.turnRight()
for i = 1,x do
turtle.forward()
turtle.up()
end
turtle.forward()
end
function stairUp(x)
curr = 0
for i = 1,x do
curr = curr+1
digcheck()
turtle.forward()
digCheckUp()
turtle.up()
digCheckUp()
inventoryOk()
end
turtle.turnRight()
turtle.turnRight()
for i = 1,x do
turtle.down()
turtle.forward()
end
turtle.forward()
end
function inventoryOk()
local inv = turtle.getItemCount(15)
if inv >= 1 then
invDump()
end
end
function invDump()
local chest = turtle.getItemCount(16)
if chest >= 1 then
turtle.select(16)
digCheckUp()
turtle.placeUp()
for i = 1 , 15 do
turtle.select(i)
turtle.dropUp()
end
turtle.select(16)
turtle.digUp()
turtle.select(1)
else
goBack()
term.clear()
term.setCursorPos(1,1)
print("no more space master")
return
end
end
if ud == "up" then
stairUp(x)
elseif ud=="down" then
stairDown(x)
end
at this point im so stuck, i started lua friday of last week so im obviously missing something important here. a helpful response will be so so appreciated. thanks again to anybody willing to take a look. also please, try it out for yourselves. see what results you get, its very odd D:
edit- wrong code was put in (earlier version) -most recent version input (same problems)
Edited on 24 February 2014 - 07:11 AM