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

[Lua] [Questions/Problems] Mining Turtles..

Started by ProblematicSolutions, 12 December 2012 - 06:00 PM
ProblematicSolutions #1
Posted 12 December 2012 - 07:00 PM
So I've been messing around with mining turtles recently and have been trying to make a code that cuts down 2x2 trees. I've managed to get most of it working but I'm not sure how to make it stop when it has finished cutting down the tree.. It just keeps tunneling into the ground.

I'm pretty sure there's a detect command but I'm not sure how to use it properly.

I am still new to this and learning so I'm sure there are plenty of things I could fix or do better xD

turtle.forward()
turtle.forward()
turtle.forward()
turtle.dig()
turtle.forward()
while turtle.digUp() do
turtle.up()
end
turtle.dig()
turtle.forward()
while turtle.digDown() do
turtle.down()
end
turtle.back()
turtle.back()
turtle.back()
turtle.back()

Also, how do I move the program onto a disk? :s

:-}
Edited on 12 December 2012 - 06:14 PM
Zoinky #2
Posted 12 December 2012 - 07:33 PM

local height = 0

turtle.forward()
turtle.forward()
turtle.forward()
turtle.dig()
turtle.forward()

while turtle.digUp() do
  turtle.up()
  height = height + 1 -- Keeps track of how high the turtle goes.
end

turtle.dig()
turtle.forward()

while turtle.digDown() and height > 1 do -- Makes sure that the turtle only goes down the amount of blocks it came up.
  turtle.down()
  height = height - 1
end

turtle.back()
turtle.back()
turtle.back()
turtle.back()

Try that.

EDIT: Woops, colour tags got mixed in. Fixed :3
EDIT #2: Wait a second… A 2x2 tree would be 4 blocks in total? Your code doesn't chop down 4 blocks? Did you mean 1x2?
Edited on 12 December 2012 - 06:42 PM
ProblematicSolutions #3
Posted 12 December 2012 - 07:54 PM
Well I've made it do half but because I don't know how to make it stop when it gets to the bottom I can't make it do the other half. If that makes any sense xD Thanks though! :D/>

EDIT: What about moving it from the turtle to a disk then making the turtle load it? :s
EDIT: Also when it's done it doesn't go all the way down, but that's okay I just added a turtle.down() once it's done :)/>
Edited on 12 December 2012 - 07:22 PM
Zoinky #4
Posted 12 December 2012 - 10:52 PM
Place the turtle next to a disk drive that has a disk inside > Open the turtles terminal > Type in 'mv <program name> disk/<program name>'
That should work. But then again, I don't really mess around with disks. Oh and, you can change the 'and height > 1' bit of the code to 'and height > 0', Sorry, wasn't thinking straight. :P/>

EDIT: If you're trying to get the turtle to keep it's program you can use the label feature. Just type 'label set <name of turtle>'. You can name the turtle anything you want. It will keep it's programs when it's broken/placed.
ProblematicSolutions #5
Posted 13 December 2012 - 12:04 AM
Yes! thank you so much! :D/>
ProblematicSolutions #6
Posted 16 December 2012 - 04:30 AM
I've used the same code for a turtle on a server and any movement commands like turtle.forward() or turtle.down() don't work. Is there a bug with turtles on multiplayer servers?
theoriginalbit #7
Posted 16 December 2012 - 04:35 AM
other option is use turtle.select( slotNum ) where slotNum is one you know is wood and then use

if not turtle.compareDown() then
  -- reached bottom layer
end
ProblematicSolutions #8
Posted 16 December 2012 - 05:24 AM
What about the server issue ? :s
theoriginalbit #9
Posted 16 December 2012 - 05:34 AM
What about the server issue ? :s

oh sorry didnt see that post.
Is the server running 1.4? If so do they have fuel enabled? if so, have your refuelled your turtle?
ProblematicSolutions #10
Posted 16 December 2012 - 05:35 AM
Yes, yes and yes. It has has 90k fuel.

I've checked the code a few times and even tried re-writing the whole thing just in case there was something I had missed.
theoriginalbit #11
Posted 16 December 2012 - 05:37 AM
in the terminal type the following 2 lines hitting enter after each

lua

turtle.forward()

what does it say? true? false?
ProblematicSolutions #12
Posted 16 December 2012 - 05:39 AM
Hm, when I did it on my single player world I was using redwood trees and it was working… and I was testing it on jungle trees on the server and I wasn't working… I just tested it on a redwood tree on the server too and it works fine.. :s
ProblematicSolutions #13
Posted 16 December 2012 - 05:47 AM
NOTE: Still isn't perfect, having a little trouble with it.
theoriginalbit #14
Posted 16 December 2012 - 05:48 AM
Hm, when I did it on my single player world I was using redwood trees and it was working… and I was testing it on jungle trees on the server and I wasn't working… I just tested it on a redwood tree on the server too and it works fine.. :s
odd o.O



NOTE: Still isn't perfect, having a little trouble with it.

whats wrong?
ProblematicSolutions #15
Posted 16 December 2012 - 06:02 AM
Still having issues with moving.. :/
theoriginalbit #16
Posted 16 December 2012 - 06:20 AM
sorry not too sure whats wrong. i had heard of a bug where turtles couldnt move in "The End" on SMP if your there.
ProblematicSolutions #17
Posted 16 December 2012 - 09:59 AM
Nope, regular world :P/> I'll play around with them some more :P/>