I need help getting a turtle to detetct if a block is above it and if true to dig upwards and if false to print "can not move".
Jump to content
I suggest you read through the tutorial resources on the computer craft wiki: http://computercraft.../wiki/Tutorials
You should be able to do something like
If (turtle.detectUp()) Then turtle.digUp() Else Print("cannot move") End
Though you probably want a while loop instead.
turtle.refuel() print("Refueled turtle!") while turtle.detectUp() do print("Digging up!") turtle.digUp() print("Going up!") turtle.up() end print("finished")
That first script will do exactly what you requested. However, what you're requesting seems a little unusual, and I'd probably start with trying to figure out at least a little more detail in what you're trying to do.
As for the second script, it will provide a bit more power to your turtle's capabilities, although keep in mind when doing that is gravity blocks, like sand and gravel, can cause the turtle to fail to move up even though it successfully dug up (unbreakable blocks like end portal frame and thaumcraft glass can also cause it to claim it goes up even though it doesn't). If we check the return value of turtle.up() we can see if it actually went up. Also, we can check the return value of turtle.digUp() as a shortcut to detectUp. For instance, if you're trying to just get a turtle to move up a single block, and dig if a block is in the way:
while (!turtle.up()) do turtle.digUp() end
Of course, this will cause the turtle to lock up if an undiggable block is in the way, but hopefully you know not to try to call the script in that situation!
0 members, 0 guests, 0 anonymous users