Jump to content




loop dont work


  • You cannot reply to this topic
5 replies to this topic

#1 gheotic

  • Members
  • 64 posts
  • LocationDenmark

Posted 02 January 2013 - 05:01 AM

Hello everyone who is reading this i have some problems with my program

im trying to make a mining turtle to dig a tunnel, but it dosnt perform a loop correctly
i have tried testing it out by putting some gravel in front of it but it only dig 1 gravel out then carry on the script

local fuel = 1
local x = 0

term.clear()
term.setCursorPos(1,1)
print("Turtle has started")
function getFuel()
if turtle.getFuelLevel() <=10 then
turtle.select(1)
turtle.refuel(2)   
end
end
function Detect() -- this function
while turtle.detect() do
turtle.dig()
end
end
getFuel()
turtle.up()
while x < 16 do --digging the tunnel
Detect()
turtle.forward()
turtle.digDown()
turtle.turnRight()
Detect()
turtle.forward()
turtle.turnLeft()
turtle.digDown()
Detect()
turlle.forward()
turtle.digDown()
turtle.turnLeft()
Detect()
turtle.forward()
turtle.turnRight()
turtle.digDown()
x = x + 1
end


#2 GopherAtl

  • Members
  • 888 posts

Posted 02 January 2013 - 05:10 AM

there's a bit of a delay between digging and gravel falling into the new space to be detected. The simplest and most reliable way to dig through any amount of gravel is to make turtle.forward() the condition, like this...

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


#3 W00dyR

  • Members
  • 135 posts

Posted 02 January 2013 - 05:11 AM

You need to put a delay in the detect() function, else it digs a block, instantly detects (while gravel, as an entidy, is falling) and doesnt see anything, so continues.

Best way to do this is after turtle.dig(), add sleep(0.5)

#4 gheotic

  • Members
  • 64 posts
  • LocationDenmark

Posted 02 January 2013 - 05:25 AM

View PostW00dyR, on 02 January 2013 - 05:11 AM, said:

You need to put a delay in the detect() function, else it digs a block, instantly detects (while gravel, as an entidy, is falling) and doesnt see anything, so continues.

Best way to do this is after turtle.dig(), add sleep(0.5)

oh thanks alot :D

#5 ChunLing

  • Members
  • 2,027 posts

Posted 02 January 2013 - 04:10 PM

If you can use your movement function to detect the gravel, that's a bit more convenient. But for digging gravel that is falling into a space that you want cleared but won't be moving into, using detect with a sleep is better.

#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 02 January 2013 - 10:05 PM

View PostW00dyR, on 02 January 2013 - 05:11 AM, said:

You need to put a delay in the detect() function, else it digs a block, instantly detects (while gravel, as an entidy, is falling) and doesnt see anything, so continues.

Best way to do this is after turtle.dig(), add sleep(0.5)

sleep(0.4) is the least time it needs, for maximum speed.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users