Jump to content

Welcome to FTB Forums
Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. If you already have an account, login here - otherwise create an account for free today!
Photo

Turtle help please


  • This topic is locked This topic is locked
2 replies to this topic

#1
slidy333

slidy333

    Newbie

  • Members
  • Pip
  • 1 posts
  • IGN:slidy333
  • Modpack:FTB Ultimate

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".

 



#2
Iamtk421

Iamtk421

    Advanced Member

  • Contributor
  • PipPipPip
  • 193 posts
  • Modpack:MindCrack Pack

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.

 

E.g.

turtle.refuel()
print("Refueled turtle!")
while turtle.detectUp() do
print("Digging up!")
turtle.digUp()
print("Going up!")
turtle.up()
end
print("finished")


#3
Kahless61

Kahless61

    Advanced Member

  • Contributor
  • PipPipPip
  • 101 posts
  • Modpack:FTB Ultimate

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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users