Posted 13 December 2012 - 05:28 PM
The program I'm trying to write is a quarry-type program. I'm trying to make it with as few lines as possible. This is my first program.
I think the problem is because I'm trying to use a while statement inside of an if-then statement, but I'm not exactly sure.
This is a quick video I made to show what happens when the program runs that way you don't have to try it yourself: [media]http://www.youtube.com/watch?v=3FN99-zfmpw[/media]
(I apologize for the ads on it, I tried to disable it, but YouTube put it on there automatically.
This is the pastebin code, if you want to fool around with it in game: http://pastebin.com/UN18uSna
and finally, here's the code:
I think the problem is because I'm trying to use a while statement inside of an if-then statement, but I'm not exactly sure.
This is a quick video I made to show what happens when the program runs that way you don't have to try it yourself: [media]http://www.youtube.com/watch?v=3FN99-zfmpw[/media]
(I apologize for the ads on it, I tried to disable it, but YouTube put it on there automatically.
This is the pastebin code, if you want to fool around with it in game: http://pastebin.com/UN18uSna
and finally, here's the code:
local x, y, z
local width, length, depth = 0, 0, 0
local xPos, yPos, zPos = 0, 0, 0
function digLevel(w, l, d)
x=0
y=0
z=0
turtle.down()
while z < tonumber(d) do
while x < tonumber(w) do
if y > 0 then
while y< tonumber(l) do
digOn()
y = y + 1
end
else
while y>0 do
digOn()
y=y-1
end
end
newRow(y)
x=x+1
end
goDown(x,y)
x=0
y=0
end
end
function newRow(yy)
turtle.digDown()
if yy>1 then
turtle.turnRight()
else
turtle.turnLeft()
end
turtle.forward()
turtle.digDown()
if yy>1 then
turtle.turnRight()
else
turtle.turnLeft()
end
end
function digOn()
turtle.digDown()
turtle.forward()
end
function goDown(xx,yy)
if yy>1 then
turtle.turnRight()
while yy > 0 do
turtle.forward()
yy=yy-1
end
turtle.turnLeft()
else
turtle.turnRight()
end
while xx > 0 do
turtle.forward()
xx = xx - 1
end
turtle.down()
turtle.digDown()
turtle.turnRight()
end
term.write("What is the width of your quarry? ")
width = read()
term.write("What is the length of your quarry? ")
length = read()
term.write("How deep? ")
depth = read()
digLevel(width, length, depth)