3 posts
Posted 12 September 2012 - 05:40 AM
Alright, so thanks to some additional help from you guys I have finished this program, and it is quite awesome and easy for me now in the building area.
Also admittedly, yes it is very slow and if it doesn't finish the floor in one shot it'll resume it's placing by going over the already placed blocks. Also in addition the inventory scanning makes it move even slower, but for those who have large floors and other stuff to get done it'll reload from the chest, until it finishes the whole "level" if you will. Thanks for the help again friends, hope you like the levels.
To use this just place a disk drive in the most upper left corner, just to the right of it place a chest with enough of the item to place in it.
Under the disk drive place the turtle so it's facing the wall.
then place a redstone torch in the upper right corner, a layer beneath where the turtle was place.
[attachment=473:level.txt]
17 posts
Posted 12 September 2012 - 06:17 AM
I looked at your code and tried it out I think the problem is
for s = 1,16 do
if turtle.getItemCount(s)== 0 then
s=s+1
turtle.select(s)
end
s=1 when you start the loop so if you do the operation:s=s+1 16 times you get s=17
then your turtle tries turtle.select(17)
turtles don't have 17 slots…
it works if you change all values of 16 to 15 that way your turtle doesn't get stuck on selecting a slot that doesn't exist.
for example
for s = 1,15 do
if turtle.getItemCount(s)== 0 then
s=s+1
turtle.select(s)
end
89 posts
Posted 12 September 2012 - 10:04 AM
you don't need to change the variable from the loop inside the loop:
for s = 1,16 do
if turtle.getItemCount(s)>=1 then
turtle.select()
end
end
this will do the same :)/>/>
btw: if you have some code more than once you can make it a function^^
example:
(in the beginning of the file)
function selectItem()
for s = 1,16 do
if turtle.getItemCount(s)>=1 then
turtle.select()
end
end
end
and then use selectItem() to call it :P/>/>
871 posts
Posted 12 September 2012 - 10:40 AM
Probably ought to add break after turtle select, so once it finds and selects a slot it doesn't check all the remaining slots.
3 posts
Posted 12 September 2012 - 03:37 PM
thanks guys I had been looking at the for loop and thought perhaps it was one too many but I just never worked out it out, the function thing I also thought about since its in a lot of coding, but I just didn't plain know how it works, and as for the break I literally have no idea how to implement that, so if you could give me an example that would help, the whole searching the entire inventory every time was getting a bit annoying. Thanks again, so far my favorite forum.
3 posts
Posted 13 September 2012 - 02:40 PM
so the result of changing that to 15 from 16 in that for loop is the loop now does not stop, what I need to have happen is the loop essentially places blocks until the inventory runs out, thanks again in advance.
17 posts
Posted 14 September 2012 - 04:59 AM
I think this is a good starting point for that
repeat
--your code here
until turtle.getItemCount(0)
Of course you need some type of function for all blocks reaching zero but it's a start.
1 posts
Posted 14 September 2012 - 06:56 AM
Alright so I did some playing around. This of course will only work if the turtle hits a wall. So it is only coded to work for a square hole like in your picture. It doesn't resume where it left off though. I'm a bit tired so while I'm pretty sure this works, it might not be perfect. I hope it helps at least. The one thing to look at is the inv() function since it finds the first item stack.
-- start functions
function inv() -- this will find the first stack of items
for i = 1,16 do
cur = i
turtle.select(i)
if turtle.getItemCount(i) >= 1 then
return(i)
end
end
return(0)
end
function home() -- this should return the turtle to the start position
back()
turtle.turnRight()
back()
turtle.turnLeft()
end
function place() -- This gets item count and if it's 0 it runs the inv function to get the next stack
if turtle.getItemCount(cur) == 0 then
turtle.select(inv())
end
turtle.placeDown()
end
function forward() -- instead of just using turtle.placeDown() we run the place function so it can check inventory stacks
place()
while turtle.forward() do
place()
end
end
function back() -- same as forward but moves backwards
place()
while turtle.back() do
place()
end
end
function move() -- This moves the turtle forward checks right if it can it moves right then back.
forward()
turtle.turnRight()
if turtle.detect() then
turtle.turnLeft()
back()
turtle.turnLeft()
if not turtle.detect() then
forward()
end
turtle.turnRight()
x = false
return(x)
else
place()
turtle.forward()
turtle.turnLeft()
end
back()
turtle.turnRight()
if turtle.detect() then
back()
turtle.turnLeft()
x = false
return(x)
else
place()
turtle.forward()
turtle.turnLeft()
end
end
--end functions
cur = 1 -- the cur variable keeps track of the current slot and is changed in the inv() function
x = true -- this variable allows the loop to exit when needed. Like on returning home.
turtle.select(1)
while x == true do
move()
end