This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Ampix0's profile picture

Coding made easy with SmartTurtleOS (Turtle Programming)

Started by Ampix0, 18 May 2013 - 03:30 PM
Ampix0 #1
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.
ETHANATOR360 #2
Posted 19 May 2013 - 03:08 PM
the normal turtle code is almost the same thing turtle.forward() = smartMoveForward() although there may be some under the hood changes to your api im not sure
jesusthekiller #3
Posted 19 May 2013 - 04:56 PM
Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…
Symmetryc #4
Posted 19 May 2013 - 05:05 PM
Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…
Actually, stos.smartDig() ;)/>. But yeah, same thing.
Ampix0 #5
Posted 19 May 2013 - 09:44 PM
Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…
Actually, stos.smartDig() ;)/>. But yeah, same thing.

No you do not type STOS.smartDig()

It's in the setup file of the turtle. it works just as typed.

If you read the STOS page you will see why this is smarter. The code above will NOT work with normal turtle functions if the turtle runs into a mob, runs out of fuel, or sand/gravel. This program is simple but robust.

Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…

Read the STOS page to learn the advantaged of using STOS over the default dig method.
Symmetryc #6
Posted 19 May 2013 - 09:54 PM
Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…
Actually, stos.smartDig() ;)/>. But yeah, same thing.

No you do not type STOS.smartDig()

It's in the setup file of the turtle. it works just as typed.

If you read the STOS page you will see why this is smarter. The code above will NOT work with normal turtle functions if the turtle runs into a mob, runs out of fuel, or sand/gravel. This program is simple but robust.

Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…

Read the STOS page to learn the advantaged of using STOS over the default dig method.
I guess, seeing as half of the people that use CC don't know Lua, but if someone does know Lua, there really isn't much difference. I'm not trying to be mean or discouraging or anything, but most of the functions are 4 lines or so and to ask of others to include it in their programs is a little much. But, what do I know? With a couple of updates, this could be as good as gold ;)/>.
Ampix0 #7
Posted 19 May 2013 - 10:31 PM
Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…
Actually, stos.smartDig() ;)/>. But yeah, same thing.

No you do not type STOS.smartDig()

It's in the setup file of the turtle. it works just as typed.

If you read the STOS page you will see why this is smarter. The code above will NOT work with normal turtle functions if the turtle runs into a mob, runs out of fuel, or sand/gravel. This program is simple but robust.

Was it ever harder to type `turtle.dig()` instead of `smartDig()`? I don't think so…

Read the STOS page to learn the advantaged of using STOS over the default dig method.
I guess, seeing as half of the people that use CC don't know Lua, but if someone does know Lua, there really isn't much difference. I'm not trying to be mean or discouraging or anything, but most of the functions are 4 lines or so and to ask of others to include it in their programs is a little much. But, what do I know? With a couple of updates, this could be as good as gold ;)/>.

I am still working with it. And it is only a few lines absolutely. The reason I made it, was because I will write those same lines for EVERY program I write. So why not build it in right? That's where I am coming from. So far it's just smart movement and height tracking, but if you code more than one program, it saves you time.
angellus #8
Posted 30 May 2013 - 03:42 PM
Not to sound like a prick or anything (delete this post if you want), just trying to fix some programming terminology here, but Notepad++ and the in-game editors are NOT IDEs. It might sound like a little thing, but you do not want to confuse the newer programmers who should actually know the difference between the two. Notepad++, Notepad or any standalone text editor (even if it is a programming notepad) it just an editor. An IDE is an "Integrated Development Environment". It has features beyond what a normal text editor does, like auto-complete, debugging, compiling, ad running/testing. Notepad++ and some other editors have basic auto-complete, but they do not have the fancy complex ones that tell you what the parameters are, where the function comes from, what it does, and other stuff.
knolle93 #9
Posted 30 May 2013 - 04:12 PM
Thanks for your example, now i have a little clue how to programm my turtle :)/>
Imque #10
Posted 02 June 2013 - 05:52 AM
Personally. I don't see the point of this. Really its performing the exact actions of the turtle API.