Posted 18 May 2013 - 05:30 PM
Have you wanted to make programs for your turtle but were scared of how difficult it is to perform certain actions?
Using SmartTurtleOS, coding is easy!
This tutorial assumes you have a basic understanding of programming
Step 1. Install STOS
STOS also known as SmartTurtleOS is a smart OS enhancement for the turtle that makes coding easy. Check out this thread to get the latest STOS and see how to install it.
Step 2. Open an IDE
And IDE is an environment in which you write your code. There are many in-game editors you can find in the program section here, but I like you use Notepad++. If you use Notepad++ there is an option at the top that says "language" and you can change this to LUA so that the syntax coloring is shown correctly.
Step 3. Write your first program.
Using STOS we can make a complex program quickly and simply. So just to make something really simple, let's just write a program that makes a hallway underground. To keep this really simple, we will make a fixed hallway three block wide by twenty long and we'll make it three blocks high as well.
1. Make a mining turtle and place him facing the wall we want to turn into a hallway.
2. Install STOS as mentioned above
3. Open Notepad++
To make this as efficient as possible let's move the turtle up one so he can dig above and below him, that way he doesn't need to make three passes at different heights. Remember that each movement costs fuel, so try to use the least amount of movement you can. So first we write the move up command using STOS functions.
smartMoveUp()
This will move our turtle up, even if something is above it. And if the turtle needs fuel, he'll get it from slot 1.
Now we need him to move forward 20 spaces clearing above and below him. So since we have three actions here, we need to create a loop. In fact, since we are going to do this more than once, let's make a function.
function threehigh()
smartMoveForward()
smartDigUp()
smartDigDown()
end
So we create a function an name it whatever we want, I'll name this "threehigh" and we told the turtle to move forward once, and dig above and below it. Then we let LUA know the function is over by writing "end". Simple!
Now, we want this to happen 20 times, so let's tell the program to call this function 20 times.
for i=1,20 do
threehigh()
end
Basically, we created a counter "i" that starts at one, calls the function we made and hits the end, and then becomes 2, repeats and becomes 3.. so on until i is twenty.
Turning around is simple.
turtle.turnLeft()
smartMoveFoward()
turtle.turnLeft()
What is great is this reads out as plain english. The turtle turns left, moves one forward and turns left again. Now he is ready to come back. How could we do that?We can use the loop again! But wait.. if we are going to use the loop again… could we just make that a function? We sure could! See if you can figure it out :D/>.
At this point your turtle has made a hallway 2x3x20.
Try to spin your turtle around and make the last pass.