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

Problem with Stripmine program - Help

Started by jackpactom, 02 April 2013 - 04:30 AM
jackpactom #1
Posted 02 April 2013 - 06:30 AM
Hello everyone, i just made a simple program to do some stripmine (http://pastebin.com/Np2wXwQG) but, when the turtle encounters gravel, the length of the tunnel decreases and everything fails… So, i was wondering if someone could give a function i which i could deal with gravel/sand, etc. :D/>
SuicidalSTDz #2
Posted 02 April 2013 - 06:35 AM
I think, there may be a tutorial on this or possibly a post in Ask A Pro about this, but I am not sure. If there isn't, I know there are programs in the Turtle section that deal with this. Look at their code and learn from it. Or if someone who has made a script to deal with gravel comes to this topic, they can share their knowledge on the topic at hand.
jackpactom #3
Posted 02 April 2013 - 06:45 AM

local function moveFoward()
while no turtle.forward() do
  turtle.dig()
  turtle.attack()
 end
end

I saw this in a post, i don't know if this is correct. If it is, i want to know how to add this in my program
SuicidalSTDz #4
Posted 02 April 2013 - 06:48 AM
You would just have to ditch the default turtle.forward() function and make your own:

local function forward()
 while not turtle.forward() do
  turtle.dig()
  turtle.attack()
 end
 turtle.forward()
end
So instead of calling turtle.forward(), call forward() and it will wait until it can move. This should not mess up the program unless you are using variables to track the turtle's movement.. If you are just say so and I will try to be of some assistance

EDIT: You should be fine, you are using repeat loops to carry out your program, a while loop executing in the background should not conflict with your main loops.

EDIT: Look at the new function I just made, noticed a problem. You will need turtle.forward() at the end of the while loop

Ok, let's review:
We define a function 'forward'
If the turtle cannot move forward it will dig and attack until it can move
we then move the turtle forward, indicating he carried out the forward function successfully
jackpactom #5
Posted 02 April 2013 - 06:55 AM
So, how it will be the final product in my pastebin?
Can you do that, because I'm new to lua and i don't know how to add it
SuicidalSTDz #6
Posted 02 April 2013 - 06:59 AM
This should be good:


local function forward()
 while not turtle.forward() do
  turtle.dig()
  turtle.attack()
 end
 turtle.forward()
 sleep(0.5)
end

function turtleMove()
 turtle.dig()
 forward()
 turtle.digUp()
 turtle.digDown()
end

while true do
for i = 1,20 do
  turtleMove()
end
turtle.turnRight()

for i = 1,3 do
  turtleMove()
end
turtle.turnRight()
for i = 1,20 do
  turtleMove()
end
turtle.turnRight()
for i = 1,2 do
  turtleMove()
end
for i = 1,2 do
  turtle.turnRight()
end
forward()
forward()
for i = 1,3 do
  turtleMove()
end
turtle.turnLeft()
end
You may want to add some sleep() function calls to compensate for falling gravel (I added one in for you)
jackpactom #7
Posted 02 April 2013 - 07:04 AM
TYVMMM, you are my hero <3
SuicidalSTDz #8
Posted 02 April 2013 - 07:09 AM
No probs :)/> If you have any other questions regarding the code or need more help, feel free to ask any of us. It's why we're here ^_^/>
jackpactom #9
Posted 02 April 2013 - 07:19 AM
One more thing, i'll use this in a server, so should i make the sleep of 1 sec?
SuicidalSTDz #10
Posted 02 April 2013 - 07:23 AM
One more thing, i'll use this in a server, so should i make the sleep of 1 sec?
It shouldn't make a HUGE difference (If you are only running one turtle that is). If you want to you can, the turtle will just be a wee-bit slower.
jackpactom #11
Posted 02 April 2013 - 07:29 AM
Ok ty ;)/>
SuicidalSTDz #12
Posted 02 April 2013 - 07:33 AM
Np ;)/>
jackpactom #13
Posted 02 April 2013 - 07:37 AM
Hey
The problem is still here, i don't know what to do
SuicidalSTDz #14
Posted 02 April 2013 - 07:41 AM
That should have solved it? Let me try something real quick.
jackpactom #15
Posted 02 April 2013 - 08:23 AM
Any news?
SuicidalSTDz #16
Posted 02 April 2013 - 08:25 AM
I just downloaded ComputerCraft to test this first hand.

I see the problem, I just can't really understand how to fix it. (I don't normally use turtles that much :P/>) If I think of something i'll let you know.
jackpactom #17
Posted 02 April 2013 - 08:42 AM
Ok ty