64 posts
Posted 13 October 2012 - 02:48 AM
When I run the following program, it should go down to the bottom of the hole and fill it on the way up. I put 64 charcoal in slot 13 and 64 dirt in all the rest before running it.
Help if possible please.
--[[ Program name : fill
This program moves 1 forward then
moves down to lowest open space and then
fills with dirt/etc back up to where it started
--]]
--[[ Be sure the turtles has the following items
in the correct slots...
slot 13 has 64 coal/charcoal
other slots (at least 1) has filler (dirt/etc)
--]]
function refuel()
fuellvl = turtle.getFuelLevel()
if fuellvl<100 then
amtchar = turtle.getItemCount(13)
if amtchar > 1 then
turtle.select(13)
turtle.refuel(2)
turtle.select(1)
else
if amtchar > 0 then
turtle.select(13)
turtle.refuel(1)
turtle.select(1)
end
end
end
end
--[[ set numeric var's --]]
fuellvl = 0
amtchar = 0
downMoves = 0
X = 0
fillSlot = 0
--[[ move forward one --]]
refuel()
turtle.forward()
--[[ for first move, it might have to dig through something
as I may have sealed a deep hole --]]
if turtle.down() == false then
turtle.digDown()
end
--[[ move down as far as it can --]]
while not turtle.detectDown() do
refuel()
turtle.down()
downMoves = downMoves + 1
end
--[[ move up and fill --]]
while downMoves > 0 do
refuel()
turtle.up()
fillslot = 0
for X = 1,16 do
if X ~= 13 then
if turtle.getItemCount(X) > 0 then
fillslot = X
end
end
end
if fillslot > 0 then
turtle.select(fillSlot)
turtle.placeDown()
end
downMoves = downMoves - 1
end
212 posts
Location
Dallas, Tx
Posted 13 October 2012 - 05:41 AM
is this code only suppose to execute once and fill one hole?
and
fillSlot = 0
should be set to 1 since there isnt a slot 0 on the turtle
8543 posts
Posted 13 October 2012 - 06:17 AM
I'm not seeing any major problems with the code. What are the states of the various variables as it gets stuck at the bottom, especially downMoves? Does it move up once?
64 posts
Posted 13 October 2012 - 02:06 PM
Lyqyd - I do not know the states of the variables or how to check that. It does move up once.
Cozzimoto -
I originally intended to have fillslot remain zero until it found "filler" like dirt in a slot, then switch to that slot and use the dirt to fill on the way up. I figured that if it remained zero, when it hit the line that said " if fillslot > 0 then " … then it would skip the line that used fillslot in the select command.
I went down to my stuck turtle, and right clicked on it. It had stopped because the fillslot variable was "out of range" at zero. So there is an issue here somewhere.
I went ahead and changed the two code lines where fillslot was set to zero, and changed it to being set to one.
Then I ran some tests.
1.) With the turtle with 64 dirt in all slots (except 64 charcoal in slot 13), I ran it. It goes down and comes up with dirt until it has used up all of the dirt in slot 1, then it returns to the top level it started at leaving a gap between it and the spot it ran out of dirt.
2.) Just to see what would happen, I then moved the turtle back 1 square (so it would go down the same hole again), and refilled slot 1 with dirt and ran it. It went down to the spot where it had stopped filling dirt and it filled it the rest of the way up. HOWEVER it stopped one square too low. The turtle ended one layer lower than where it started.
3.) Then I started over and ran the turtle in a new hole, with Nothing in slot 1, and dirt in all other slots (except charcoal in 13). It placed one dirt (probably the one it dug out before it headed down), then returned all the way to the correct starting layer but filled in no other dirt from other slots.
Although it does run now without erroring out, when it runs out of dirt in slot 1 I want it to look for any item in any other slot (except 13 where the fuel is) and use that stuff to fill the hole.
Please let me know if you all have any ideas how to fix these issues. Thanks !
55 posts
Posted 13 October 2012 - 02:40 PM
if not turtle.placeDown() then
fillslot = fillslot + 1
if fillslot == 13 then
fillslot = 14
end
end
The first if statement will make the turtle attempt to place a block, and if it fails to, then the condition will be met.
that should make it so that if there is nothing to place, then the fillslot will increase by 1.
This will only work if 13 is the only slot that wouldn't have filler in it, although you could of course add other exceptions.
64 posts
Posted 13 October 2012 - 04:35 PM
I adjusted the code and got the following error…
fill:64: attempt to perform aritchmetic _ _ add on nil and number
Here is my revised code. Please help, and thank you for your time on it so far. I think we are close.
--[[ Program name : fill
This program moves 1 forward then
moves down to lowest open space and then
fills with dirt/etc back up to where it started
--]]
--[[ Be sure the turtles has the following items
in the correct slots...
slot 13 has 64 coal/charcoal
other slots (at least 1) has filler (dirt/etc)
--]]
function refuel()
fuellvl = turtle.getFuelLevel()
if fuellvl<100 then
amtchar = turtle.getItemCount(13)
if amtchar > 1 then
turtle.select(13)
turtle.refuel(2)
turtle.select(1)
else
if amtchar > 0 then
turtle.select(13)
turtle.refuel(1)
turtle.select(1)
end
end
end
end
--[[ set numeric var's --]]
fuellvl = 0
amtchar = 0
downMoves = 0
X = 0
fillSlot = 1
--[[ move forward one --]]
refuel()
turtle.forward()
--[[ for first move, it might have to dig through something
as I may have sealed a deep hole --]]
if turtle.down() == false then
turtle.digDown()
end
--[[ move down as far as it can --]]
while not turtle.detectDown() do
refuel()
turtle.down()
downMoves = downMoves + 1
end
--[[ move up and fill --]]
while downMoves > 0 do
refuel()
turtle.up()
if not turtle.placeDown() then
--[[ make the turtle attempt to place a block, and
if it fails to, then the condition will be met --]]
fillslot = fillslot + 1
--[[ If there is nothing to place, then the fillslot will increase by 1 --]]
if fillslot == 13 then
--[[ Do not fill the hole with charcoal --]]
fillslot = 14
end
end
downMoves = downMoves - 1
end
318 posts
Location
Somewhere on the planet called earth
Posted 13 October 2012 - 04:44 PM
Down in your code you have fillSlot uses as this: fillslot. But you delaared it as fillSlot. So fillslot is nil and you can't add 1 to a nil value.
64 posts
Posted 13 October 2012 - 06:27 PM
I fixed the fillSlot variable issue. (new complete code below)
However, it goes down, and comes all the way up, but there is still a gap between it's end position and the top of the stack of dirt. In other words, it still does not switch to a different stack in slot (or whatever slot the dirt happens to be in).
--[[ Program name : fill
This program moves 1 forward then
moves down to lowest open space and then
fills with dirt/etc back up to where it started
--]]
--[[ Be sure the turtles has the following items
in the correct slots...
slot 13 has 64 coal/charcoal
other slots (at least 1) has filler (dirt/etc)
--]]
function refuel()
fuellvl = turtle.getFuelLevel()
if fuellvl<100 then
amtchar = turtle.getItemCount(13)
if amtchar > 1 then
turtle.select(13)
turtle.refuel(2)
turtle.select(1)
else
if amtchar > 0 then
turtle.select(13)
turtle.refuel(1)
turtle.select(1)
end
end
end
end
--[[ set numeric var's --]]
fuellvl = 0
amtchar = 0
downMoves = 0
X = 0
fillSlot = 1
--[[ move forward one --]]
refuel()
turtle.forward()
--[[ for first move, it might have to dig through something
as I may have sealed a deep hole --]]
if turtle.down() == false then
turtle.digDown()
end
--[[ move down as far as it can --]]
while not turtle.detectDown() do
refuel()
turtle.down()
downMoves = downMoves + 1
end
--[[ move up and fill --]]
while downMoves > 0 do
refuel()
turtle.up()
if not turtle.placeDown() then
--[[ make the turtle attempt to place a block, and
if it fails to, then the condition will be met --]]
fillSlot = fillSlot + 1
--[[ If there is nothing to place, then the fillslot will increase by 1 --]]
if fillSlot == 13 then
--[[ Do not fill the hole with charcoal --]]
fillSlot = 14
end
end
downMoves = downMoves - 1
end
318 posts
Location
Somewhere on the planet called earth
Posted 13 October 2012 - 06:53 PM
--[[ Program name : fill
This program moves 1 forward then
moves down to lowest open space and then
fills with dirt/etc back up to where it started
--]]
--[[ Be sure the turtles has the following items
in the correct slots...
slot 13 has 64 coal/charcoal
other slots (at least 1) has filler (dirt/etc)
--]]
function refuel()
fuellvl = turtle.getFuelLevel()
if fuellvl<100 then
amtchar = turtle.getItemCount(13)
if amtchar > 1 then
turtle.select(13)
turtle.refuel(2)
turtle.select(1)
else
if amtchar > 0 then
turtle.select(13)
turtle.refuel(1)
turtle.select(1)
end
end
end
end
--[[ set numeric var's --]]
fuellvl = 0
amtchar = 0
downMoves = 0
X = 0
fillSlot = 1
--[[ move forward one --]]
refuel()
turtle.forward()
--[[ for first move, it might have to dig through something
as I may have sealed a deep hole --]]
if turtle.down() == false then
turtle.digDown()
end
--[[ move down as far as it can --]]
while not turtle.detectDown() do
refuel()
turtle.down()
downMoves = downMoves + 1
end
--[[ move up and fill --]]
while downMoves > 0 do
turtle.select(fillSlot)
refuel()
turtle.up()
if not turtle.placeDown() then
--[[ make the turtle attempt to place a block, and
if it fails to, then the condition will be met --]]
fillSlot = fillSlot + 1
--[[ If there is nothing to place, then the fillslot will increase by 1 --]]
if fillSlot == 13 then
--[[ Do not fill the hole with charcoal --]]
fillSlot = 14
end
end
downMoves = downMoves - 1
end
You forgot to make it select fillSlot
8543 posts
Posted 13 October 2012 - 06:53 PM
You're not having it place a block again after it fails to do so; instead, it moves up again. Try changing the if block to this:
while not turtle.placeDown() do
fillSlot = fillSlot + 1
if fillSlot == 13 then
fillSlot = 14
end
turtle.select(fillSlot)
end
64 posts
Posted 14 October 2012 - 01:43 AM
Awesome. Thanks guyz !
All is well :)/>/>