This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Bluethousandand2's profile picture

Using odd number messes with ending location.

Started by Bluethousandand2, 18 January 2014 - 01:18 AM
Bluethousandand2 #1
Posted 18 January 2014 - 02:18 AM
Oh, oh late night writing. Anyways. I made this bit of code to clear out a platform 1 thick, with the specified length and width. The problem is, though, when I make the width an odd number, the turtle ends on the opposte end of where it started. It's stupposed to end up on the right-most block (width) on the same side it started on.


local tArgs = {...}
x=0
if tArgs ~=2 then
l=tonumber(tArgs[1])
w=tonumber(tArgs[2])
for i=1,w do
for i=1,l do
turtle.dig()
turtle.forward()
end
if x%2==0 then
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
elseif x%2==1 then
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
end
x=x+1
if x==w then
abort()
end
end
else
abort()
end
OReezy #2
Posted 18 January 2014 - 03:41 AM
First off, a little indention goes a long way.

Unless I'm missing something, it looks like your problem is just the way you programmed it. You have it go up and down the rows until its finished. If its an odd number this will always have it end on the opposite side. If you want it to return you just need to add a bit of code to tell it to go back to a point.

PS: what does abort() do?
Bluethousandand2 #3
Posted 18 January 2014 - 10:11 AM
Abort just ends the program, by causing an undefined method error. I'll get to work on fixing that, I thought it was just code was acting up, but I actually just didnt make it properly
Edited on 18 January 2014 - 09:12 AM