Posted 11 January 2013 - 01:20 PM
Hey all, looking for a little help with my first programming attempt. Now I'm sure there are more elegant solutions to this, but I'm mainly just looking to fix my code..if possible. This is basically an attempt to copy functionality that Guude put up a few days ago. Turtle starts in one corner of a 12 X 12 square, moves to the center, places bone meal (located in slot 1 of his inventory), proceeds to the bottom left corner of the square, then "digs" each square row by row.
The problem I'm having is that after he places the bone meal he's jumping a bunch of lines of code and going right into the "turnaround" procedure call. I had original used for loops for all the initial moving around, but as I mentioned above he would jump right to the turnaround procedure call after placing the bone meal, so I elimated them and typed the movements out step by step figuring that I had screwed up a variable somewhere….but even when typing out each movement individually he is still skipping a big chunk…thoughts?
Here's the script. The bold is the part he is skipping.
The problem I'm having is that after he places the bone meal he's jumping a bunch of lines of code and going right into the "turnaround" procedure call. I had original used for loops for all the initial moving around, but as I mentioned above he would jump right to the turnaround procedure call after placing the bone meal, so I elimated them and typed the movements out step by step figuring that I had screwed up a variable somewhere….but even when typing out each movement individually he is still skipping a big chunk…thoughts?
Here's the script. The bold is the part he is skipping.
-- Seed gathering v0.1 by cdnsailorboy
-- Vars
meal = 0
local i = 11
local j = 0
local x = 2
y = 0
dir = {right, left, right, left, right, left, right, left, right, left, right, left}
-- Functions
function row()
while i > 0 do
turtle.dig()
turtle.forward()
i = i - 1
end
i = 11
end
function unload()
turnaround()
x = 2
while x < 17 do
turtle.select(x)
turtle.drop()
x = x + 1
end
turtle.select(1)
end
function turnaround()
turtle.turnRight()
turtle.turnRight()
end
function rowend()
if dir[y] == right then
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
elseif dir[y] == left then
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
end
end
-- Main Script
meal = turtle.getItemCount(1)
while meal > 0 do
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.place()
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.turnLeft()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
[b] turtle.forward()[/b]
turnaround()
for y = 1,12 do
row()
rowend()
end
unload()
meal = turtle.getItemCount(1)
end