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

Turtle Strip mine

Started by grand_mind1, 03 May 2013 - 04:42 PM
grand_mind1 #1
Posted 03 May 2013 - 06:42 PM
I am trying to make a little stripmine program. It's not the best as I am new to programming in general but it has been going well so far. I recently decided to try to make it better and more elegant.
New code:
http://pastebin.com/idQC12J9
I don't know what I've done wrong but the turtle just mines a 1x1 spaces infinitely forward. I'm sure it has something to do with my forward function but I couldn't figure it out.
Help is appreciated!
Thanks! :D/>
The_Awe35 #2
Posted 03 May 2013 - 09:44 PM
1. Use this instead of your forward function

local function forward()
	while not turtle.forward() do
	 turtle.dig()
	end
turtle.digUp()
turtle.digDown()
end

2. the least space you can have between torches without spawing mobs is 8, so I would suggest changing your torch function, but It doesn't matter much either way.
Edit: I see now that you are only placing the torch at the end of the tunnel. Not a great idea.
I would do it like this:

local function row(dist)
  for i = 1,dist do
  forward()
	if i%8==0 and torch ~= "n" then
	turtle.select(tonumber(torch))
	turlte.placeUp() -- no need for a dig up because forward() already did that for me
	end
  end
end

In case you didn't know, "%" makes a remainder. eg
7%3 = 1
8%3 = 2
9%3 = 0
So when I did i%8, I checked if the loop I was on was divisible by 8, and if it was then it would place a torch.

3. In your last while loop, you never increase curlen. I suggest doing a for loop like


for i = curlen, tunlen do
--stuff
end

Edit 2: I missed it before, but you did do something wrong on your forward() function. You need to have "curforw = curforw+1" inside of the while loop (just move that one "end" up) , but I would use the new forward function i showed you anyway.
Edited on 03 May 2013 - 08:20 PM
grand_mind1 #3
Posted 03 May 2013 - 10:35 PM
I don't know why but my turtle seems to make the main tunnel 3 times as long as it should be. For example, I tried to make the main tunnel 10 but it mined 30. I think it has to do with my loop but I can't seem to figure out what is wrong.
The_Awe35 #4
Posted 04 May 2013 - 12:18 AM
Can you show the new code please?
grand_mind1 #5
Posted 04 May 2013 - 12:23 AM
Oh, yes sorry.
New code:
http://pastebin.com/h8e9i55x
The_Awe35 #6
Posted 04 May 2013 - 12:33 AM
so it is moving to far because with the setup you have now, forward() should make it move once. get rid of the for loop in forward() and all the variables when you call it, and it will work fine.
grand_mind1 #7
Posted 04 May 2013 - 12:59 AM
But won't that make me unable to tell it how far to move forward?
The_Awe35 #8
Posted 04 May 2013 - 04:03 PM
The way I like to have it set up, is so that my forward() function only moves once, but clears up confusion with gravel and mobs/me in the way. Then I have another function (usually row()) that accesses it, and just repeats forward() how ever many times needed. I like this more, because I can use it to help me turn,

local function row()
  for i = 1,10 do
  forward()
  end
lane = lane+1
end

local function turn()
if lane%2==0 then -- checks if lane is even 
turtle.turnLeft()
forward() 
turtle.turnLeft()
else -- if lane is odd
turtle.turnRight()
forward()
turtle.turnRight()
end
place torches, (like I have shown above) and I can use it easily in another function if I want it to go forward. I use it only as a substitute for turtle.forward(), and then repeat it as necessary. The way you have it set up still works, but I don't really like how it is laid out. It is wholly up to you in any case.