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

Turtle item manipulation

Started by Rieu, 22 May 2015 - 12:27 AM
Rieu #1
Posted 22 May 2015 - 02:27 AM
Hello. I am trying to develop a program that will automatically place lava and turn it into obsidian and then harvest it. I have it almost done, however, I don't know how to make the obsidian go to the slots I chose. Also when I try to fill the fluid cells using 'while turtle.getItemCount(6) do turtle.place() end', I get "a:260: attempt to compare function with number. Also after filling them, how do I get them to stack? I am assuming that it will have the same effect as if I were to fill them. It will leave one out of the stack. All help would be appreciated.

Thanks
Ferrwolf

Spoiler–Author: Ferrwolf
– This program is designed to make obsidian in two, 2x18 trenches dug by turtle

–Checks to ensure fluid cells are where they need to be

if turtle.getItemCount(1) < 64 then
term.clear()
term.setCursorPos(1,5)
print("Please place 64 lava cells slot 1, 13 lava cells in slot 2, and 1 water cell in slot 3.")
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 64 lava cells slot 1, 13 lava cells in slot 2, and 1 water cell in slot 3.")
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 64 lava cells slot 1, 13 lava cells in slot 2, and 1 water cell in slot 3.")
sleep(2)
term.clear()
print("Once you place the items in the correct slots, please start me again.")
print("Shutting down in 3")
sleep(2)
print("2")
sleep(2)
print("1")
sleep(2)
os.shutdown()
elseif turtle.getItemCount(2) < 13 then
term.clear()
term.setCursorPos(1,5)
print("Please place 13 lava cells in slot 2, and 1 water cell in slot 3.")
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 13 lava cells in slot 2, and 1 water cell in slot 3.")
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 13 lava cells in slot 2, and 1 water cell in slot 3.")
sleep(2)
term.clear()
print("Once you place the items in the correct slots, please start me again.")
print("Shutting down in 3")
sleep(2)
print("2")
sleep(2)
print("1")
sleep(2)
os.shutdown()
elseif turtle.getItemCount(3) < 1 then
term.clear()
term.setCursorPos(1,5)
print("Please place 1 water cell in slot 3.")
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 1 water cell in slot 3.")
sleep(2)
term.clear()
sleep(1)
term.setCursorPos(1,5)
print("Please place 1 water cell in slot 3.")
sleep(2)
term.clear()
print("Once you place the items in the correct slots, please start me again.")
print("Shutting down in 3")
sleep(2)
print("2")
sleep(2)
print("1")
sleep(2)
os.shutdown()
elseif turtle.getItemCount(3) > 1 then
term.clear()
term.setCursorPos(1,5)
print("Please place only 1 water cell in slot 3. You have too many!")
sleep(2)
term.clear()
sleep(2)
term.setCursorPos(1,5)
print("Please place only 1 water cell in slot 3. You have too many!")
sleep(2)
term.clear()
sleep(2)
term.setCursorPos(1,5)
print("Please place only 1 water cell in slot 3. You have too many!")
sleep(2)
term.clear()
print("Once you place the item in the correct slot, please start me again.")
print("Shutting down in 3")
sleep(2)
print("2")
sleep(2)
print("1")
sleep(2)
os.shutdown()
end
– Turtle mines the first row of obsidian

for i=0,18 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
end

– Sets the turtle up to mine the second row

turtle.turnRight()
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.turnRight()

– Turtle mines the second row

for i=0,17 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
end

– Turtle moves the the second plot and prepares to mine the 3rd row

turtle.turnLeft()
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.turnLeft()

– Turtle mines the 3rd row

for i=0,17 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
end

– Turtle prepares to mine 4th row

turtle.turnRight()
turtle.dig()
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
turtle.turnRight()

– Turtle mines the 4th row

for i=0,17 do
while not turtle.forward() do
turtle.attack()
turtle.dig()
end
end

– Returns turtle to starting point while placing lava

turtle.select(1)

for i=0,17 do
turtle.back()
turtle.place()
end

turtle.turnLeft()
turtle.back()
turtle.place()
turtle.turnLeft()
turtle.back()
turtle.place()

for i=0,16 do
turtle.back()
turtle.place()
end

turtle.turnRight()
turtle.back()
turtle.place()
turtle.back()
turtle.place()
turtle.turnRight()

for i=0,17 do
turtle.back()
turtle.place()
end

turtle.turnLeft()
turtle.back()
turtle.place()
turtle.turnLeft()
turtle.back()
turtle.place()

for i=0,4 do
turtle.back()
turtle.place()
end

turtle.select(2)

for i=0,12 do
turtle.back()
turtle.place()
end

–Placing water to make obsidian
turtle.select(3)
turtle.up()
turtle.forward()
turtle.turnRight()
turtle.forward()
turtle.forward()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.forward()
turtle.place()
sleep(3)
turtle.place()
for i=0,9 do
turtle.forward()
end
turtle.place()
sleep(3)
turtle.place()
turtle.turnLeft()
turtle.forward()
turtle.forward()
turtle.turnLeft()
for i=0,14 do
turtle.forward()
end
turtle.up()
turtle.select(1)
turtle.place()
turtle.select(2)
turtle.place()
while turtle.getItemCount(6) > 1 do
turtle.place()
end
turtle.place()
while turtle.getItemCount(7) > 1 do
turtle.place()
end
turtle.place()
turtle.turnLeft()
turtle.turnLeft()
turtle.down()
turtle.down()
term.clear()
print("Complete!")
Edited on 22 May 2015 - 12:29 AM
HPWebcamAble #2
Posted 22 May 2015 - 03:56 AM
I don't know how to make the obsidian go to the slots I chose

I believe when a turtle picks up an item, it goes into the selected slot, or the next free one.


when I try to fill the fluid cells using 'while turtle.getItemCount(6) do turtle.place() end', I get "a:260: attempt to compare function with number.

Well, when I put it into Notepad++, this was line 260:

turtle.place()
Obviously, it won't error like that.
The line above could though, if you left out the parenthesis.
Are you sure this is the same code that generated that error?


Also when I try to fill the fluid cells … how do I get them to stack? I am assuming that it will have the same effect as if I were to fill them. It will leave one out of the stack

You mean IC2 fluid cells? (Which do stack after being filled)
You could try turtle.transferTo



Also, that's a lot of code. Would you put it on pastebin next time, and put the link here?
That way, we can see the same line numbers
Rieu #3
Posted 22 May 2015 - 04:44 AM
I don't know how to make the obsidian go to the slots I chose

I believe when a turtle picks up an item, it goes into the selected slot, or the next free one.

I will change the selected slot to see if that helps

when I try to fill the fluid cells using 'while turtle.getItemCount(6) do turtle.place() end', I get "a:260: attempt to compare function with number.

Well, when I put it into Notepad++, this was line 260:

turtle.place()
Obviously, it won't error like that.
The line above could though, if you left out the parenthesis.
Are you sure this is the same code that generated that error?


Yes I am sure. You are correct that this code is on that line, however I do believe the issue is from line 259 as that is the line that would match the error given.

Also when I try to fill the fluid cells … how do I get them to stack? I am assuming that it will have the same effect as if I were to fill them. It will leave one out of the stack

You mean IC2 fluid cells? (Which do stack after being filled)
You could try turtle.transferTo

I will give that a try. Yes I am referring to the Universal Fluid Cell 4100 from IC2. They do stack when filled with the exception of the last one. That one never moves to the stack when filled. It must be manually done.

Also, that's a lot of code. Would you put it on pastebin next time, and put the link here?
That way, we can see the same line numbers

It is on pastebin, Actually I modify the code on pastebin and download it directly from the turtle. This is the link for it.
Rieu #4
Posted 22 May 2015 - 05:21 AM
I don't know how to make the obsidian go to the slots I chose

I believe when a turtle picks up an item, it goes into the selected slot, or the next free one.

I will change the selected slot to see if that helps

That fixed the placement issue. Thanks. Now on to the error :D/>
Rieu #5
Posted 22 May 2015 - 05:57 AM
when I try to fill the fluid cells using 'while turtle.getItemCount(6) do turtle.place() end', I get "a:260: attempt to compare function with number.

Well, when I put it into Notepad++, this was line 260:

turtle.place()
Obviously, it won't error like that.
The line above could though, if you left out the parenthesis.
Are you sure this is the same code that generated that error?


Yes I am sure. You are correct that this code is on that line, however I do believe the issue is from line 259 as that is the line that would match the error given.

The problem mysteriously vanished once I started placing obsidian in the last two slots. My guess is the obsidian was messing up the comparison command. Now I am off to try to get the items to stack properly. One more thing if you could, what is the command to place items in specific slots into a chest?
Bomb Bloke #6
Posted 22 May 2015 - 06:26 AM
what is the command to place items in specific slots into a chest?

Use turtle.select() to choose the slot to place from, then use turtle.drop() while the turtle is directly next to and facing the chest.

If you instead mean "into a specific slot in the chest", ComputerCraft doesn't offer such a command. turtle.drop() places into the first slot that happens to be suitable.

The OpenPeripheral mod allows you to wrap the chest as a peripheral, and then order the chest itself to pull an item from the turtle's inventory into a specific slot of its own. A little more complex, and you may or may not have that mod.
Rieu #7
Posted 22 May 2015 - 07:13 AM
what is the command to place items in specific slots into a chest?

Use turtle.select() to choose the slot to place from, then use turtle.drop() while the turtle is directly next to and facing the chest.

If you instead mean "into a specific slot in the chest", ComputerCraft doesn't offer such a command. turtle.drop() places into the first slot that happens to be suitable.

The OpenPeripheral mod allows you to wrap the chest as a peripheral, and then order the chest itself to pull an item from the turtle's inventory into a specific slot of its own. A little more complex, and you may or may not have that mod.

The first answer was perfect. Thank you so much for all the help :D/>