Jump to content

The turtle


simong93

Recommended Posts

It's actually pretty simple, I managed to learn it without any tutorials, just by looking at other peoples programs.

if turtle.detect() then

turtle.dig()

end

turtle.forward()

Or

if turtle.detect() then

repeat

turtle.dig()

until turtle.forward() == true

else

turtle.forward()

end

The first option is clearly much more simple, but it'll bug out on sand/gravel

I'm not 100% sure the second option works, but it should account for gravel

Link to comment
Share on other sites

Why even bother with detect?

I keep forgetting the LUA stuff for NOT, so I'll just write it out

 while not turtle.forward() do

  turtle.dig()

  sleep(0.8)

end

For bonus points you can catch the output from the dig and use it to end your dig routine if it can't break the block infront of it. This is how excavate works.

Link to comment
Share on other sites

It's actually pretty simple, I managed to learn it without any tutorials, just by looking at other peoples programs.

if turtle.detect() then

turtle.dig()

end

turtle.forward()

This seems very much like php but turtle.detect() how exacly does this work does it detect anything in front of it and if there is it will then dig forward but then why would i end the quote then move forward sorry if its a dumb question im just trying to understand a bit better

Link to comment
Share on other sites

ok so its basciy yes there is something in front of me dig it once then end now move forward if there was no end would it just turn into a continues loop

also is there a easyer way of writeing this code as at the moment i have to go into the minner type lua then type the code line then enter then code then enter its such a pain can i write the code in say notepadd++ and import it into the game

My other question is say i only want him to go forward 10 blocks i would normaly for most code put loop 10(moveforward) but this dosent work

Link to comment
Share on other sites

if there was no end, the if statement would not have a stopping point, so it would never move forward OR dig if nothing was in front of it.

if you are not playing on a remote server, you can use notepad++ or similar to write the code and save it in the proper place. said place depends on the ID of the computer you're using. basically <minecraft folder>\saves\<world name>\computer\<computer ID>\

there are multiple types of loops in LUA that can repeat a given number of times. for loops are usually used for this purpose though because they're basically ready-made for it. I've never heard of a language that uses a syntax like "loop x(command)", but for loops are a very standard type of loop that exists in almost any respectable language. functionally they do that same thing as what you seem to be expressing there, though for loops are a little more flexible than that.

for loops in lua

the code for what you want would look something like this:


for x=1,10 do

  turtle.forward()

end

that would move forward 10 times.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...