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

Core Sample

Started by DZCreeper, 08 November 2012 - 02:21 PM
DZCreeper #1
Posted 08 November 2012 - 03:21 PM
This is my first time ever using ComputerCraft in Minecraft. I can't believe I didn't start before. My first program is very simple. It digs down 64 blocks, sucking any items on the ground up, and storing all the blocks. It then goes back up 64 blocks. I plan on having this be a sub program that will be repeated inside of a larger quarry program.

This is an excellent way to decide if the spot you are it is a good place for a small mine. Its not tested and I would appreciate any feedback and testing.



for I = 1, 64 do

  if turtle.detectDown()
	then

	turtle.digDown()
	turtle.suckDown()
	turtle.down()

	else

	turtle.down()

	end

end

for H = 1, 64 do
  turtle.up()

  end

Edit: Thanks for the suggestions guys. This weekend I plan on writing a more elegant version, I haven't had much time for playing games or coding lately.
sjonky #2
Posted 08 November 2012 - 03:33 PM
You don't need to specify everything in the for loop btw. you can just write for i = 1,64 do. And you dont need turtle.suckDown() as the turtle.digDown() automaticly picks up the items you dig. and you should rather use a for loop in the going up part too. would be shorter.
DZCreeper #3
Posted 08 November 2012 - 03:46 PM
Okay, so by default a for loop increments by 1? Good to know. I put turtle.suckDown() in that way if it broke a dungeon chest it would pick up the items. I will switch the going up part, that was mainly because I was trying out the different loops.
sjonky #4
Posted 08 November 2012 - 04:03 PM
Ah okey, another suggestion to you program by the way. Make it check the walls around it too. and compare it with stuff in your inventory and dig it if it's not trash. It doens't cost any fuel to turn around so it's a nice way to make the digging more effective. Also instead of just going straight back up, maybe make it move to another location below. and dig itself up again. that way you wount waste fuel just going up again doing nothing.
DZCreeper #5
Posted 08 November 2012 - 05:12 PM
I plan on doing your suggestions, this is going to be 1/3 of a quarry program. I will have a modified version of this causing the turtle to mine and put stuff in chests. Then another turtle will empty the chests and sort the stuff into my master sorting system. Finally, another turtle will run an automatic tree farm to supply wood for the chests and fuel for the turtles.
DZCreeper #6
Posted 08 November 2012 - 05:13 PM
Ok, I have a question that I really hope is easy to answer.How can I have the turtle detect bedrock? I want the turtle to start the going up part of the program when it hits bedrock, but I can't think of any way to do it.

Edit: Didn't feel this should be in the ask a pro section. The program already works, I am just asking for help with making it better.
ChunLing #7
Posted 23 November 2012 - 05:01 AM
while not turtle.down() do
    if turtle.detectDown() then
        if not turtle.digDown() then print("unbreakable block in path") return false end
    elseif turtle.getFuelLevel() == 0 then print("Out of fuel" ) return false
    else turtle.attackDown() end
    if itr8 > 64 then print("persistent impediment") return false end
    itr8 = itr8+1
end
KillaVanilla #8
Posted 23 November 2012 - 05:17 AM
Looks good for a first program.

One thing to keep in mind, though: For loops typically start at one unless there's a reason to start somewhere else.
Your program would actually go down 65 blocks.

Also, encase your code in
 tags.