simong93 Posted December 13, 2012 Posted December 13, 2012 Hi all ive been learning the lua code but i still cant get my head around the general code what i just want to learn the basics with the turtle does anyone no of any tutorials to teach me say how to move it forward and if it detects something mine
racingpro Posted December 13, 2012 Posted December 13, 2012 Direwolf20 did a little series a while back on programming the turtles. Don't know if this'll help you, but here it is anyway.
Silent Posted December 13, 2012 Posted December 13, 2012 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
Neowulf Posted December 13, 2012 Posted December 13, 2012 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.
simong93 Posted December 14, 2012 Author Posted December 14, 2012 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
Silent Posted December 14, 2012 Posted December 14, 2012 turtle.detect() returns a true if there is something there, false if not, so in this case: if there is something in front of me dig it end if move forward
simong93 Posted December 14, 2012 Author Posted December 14, 2012 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
simong93 Posted December 14, 2012 Author Posted December 14, 2012 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
freakachu Posted December 14, 2012 Posted December 14, 2012 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.
Silent Posted December 15, 2012 Posted December 15, 2012 The easiest way to get programs from Notepad++ into the game is by enabling the HTTP API in the config, then using the pastebin command
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now