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

Turtle Stop Mining Help

Started by Beardmoresam, 27 February 2012 - 06:03 PM
Beardmoresam #1
Posted 27 February 2012 - 07:03 PM
Hi, I have a turtle script I'm working on, pretty much begginers stuff. It invovles a turtle digging a nice little mineshaft down to bedrock. The turtle digs happily away but it won't stop when it reaches bedrock. Instead it keeps digging without descening, basically making a tunnel. Another issue I have is I am not that smart with events and I can't get it to stop when told which would help.

Code so far:
Spoiler–Create a mineshaft
print("Creating your mineshaft, Press any key to stop")
while true do
turtle.digDown()
turtle.down()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnLeft()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.forward()
turtle.turnRight()
turtle.dig()
turtle.turnLeft()
turtle.back()
sleep(0)
if event == "key" and param1 then
break
end
end

Any help is appreciated, thanks :D/>/>
Casper7526 #2
Posted 27 February 2012 - 07:11 PM
You need to add a check so that if it attempts to digDown and it returns false then it breaks out of the loop.


if not turtle.digDown() then break end
Beardmoresam #3
Posted 27 February 2012 - 07:25 PM
Ok thanks, as for the event at the bottom, where did I go wrong? I can't get it to work xD Thanks
Casper7526 #4
Posted 27 February 2012 - 07:39 PM
You never actually did a pull event

event, param = os.pullEvent()

but if you do that it will hold your program there until it receives an event, if you wanted to pull events and not stop your program you can do

os.queueEvent("fake")
event, param = os.pullEvent()
Beardmoresam #5
Posted 27 February 2012 - 07:44 PM
Thanks :D/>/> as you can tell, I'm pretty new to this xD
Kudendar #6
Posted 29 February 2012 - 04:34 AM
Thanks ^_^/>/> as you can tell, I'm pretty new to this xD

I loved the sleep(0). Haha. Yea once you learn functions you can loop that right there instead of calling it each time, its a ton more helpful XD.
Beardmoresam #7
Posted 29 February 2012 - 08:52 PM
The idea oft he sleep(0) was to allow the mod to do other processes than just that script, if not it gets stuck doing that one alone and there is no point in the program where is stops for however long to allow other programs to run. I don't know if that's neccesary in Lua though xD if not, I can see why I look even more a newb xD
Liraal #8
Posted 29 February 2012 - 09:10 PM
type sleep(0.1) instead
Beardmoresam #9
Posted 29 February 2012 - 09:57 PM
ah ok, thanks :unsure:/>/> I thought the sleep command would be enough to take care of that but I'll go with your advice xD Thanks B)/>/>