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

SmartTurtleOS 2.0 (Code your program for STOS!)

Started by Ampix0, 12 May 2013 - 04:02 PM
Ampix0 #1
Posted 12 May 2013 - 06:02 PM
Hey all, I am completely new to computer craft and to LUA. I am not a programmer except maybe sometimes by hobby, but here we go. I tried to make a turtlebot and then I noticed… it was really stupid, it constantly got messed up by sand and gravel and all types of little things. So I made a smarter Turtle. I am not sure if there is a way to edit the actual Turtle OS but I was advised here just to edit the start up, so here it is.

Code: http://pastebin.com/5ZMaTQB3

Description:
Version 2.0 of SmartTurtleOS

​ Persistence in moving (Will always move in the direction indicated even if path is blocked)

Persistence in digging (Will dig as long as there is a block to counter sand/gravel)
Ability to track vertical movement
Able to move more than 1 block at a time.

Stays fueled at all times. currently supports 1 stack of fuel in slot 1



Dear Coders!

Write your programs for the SmartTurtleOS! Simply use the commands listed below and have your user install SmartTurtleOS! Use SmartTutleOS to shorten your code and increase efficiency. SmartTurtleOS is being updated often to be as efficient as possible without changing functionality! Which means you do not need to worry that your code will not work with newer versions.


To Track Height:
When writing your program for a turtle running SmartTurtleOS 2.0 initialize height to 0 at the beginning of your code. When you use the smart movement functions, differences in height will be added and subtracted to height.
Example:

height = 0
smartMoveDown()
smartMoveDown()
smartMoveDown()
smartMoveDown()
smartMoveDown()
print(height)
height is now equal to -5

API
smartRefuel()
Checks if fuel level is below 1 and refuels from slot 1 if needed.

smartDig()
Will clear the space in front of the turtle, taking into consideration falling blocks as well.

smartDigUp()
Will clear the space above the turtle, taking into consideration falling blocks as well.

smartDigDown()
Will clear the space below the turtle with the same persistence as the other movements.

smartMoveForward(distance int)
Uses smartRefuel(), Moves the turtle forward with persistence. Will attack or dig to get to the distance passed to it.

smartMoveUp(distance int)
Uses smartRefuel(), Moves the turtle up with persistence. Will attack or dig to get to the distance passed to it. Adds to the height counter.

smartMoveDown(distance int)
Uses smartRefuel(), Moves the turtle down with persistence. Will attack or dig to get to the distance passed to it. Subtracts from the height counter.

How To Install STOS
  1. Create your turtle.
  2. Right-click the turtle and type in "Pastebin get 5ZMaTQB3 startup"
  3. Type "Reboot"
You've done it! You can now enjoy the benefits of the SmartTurtleOS!
nutcase84 #2
Posted 12 May 2013 - 08:48 PM
This is good for a beginner, good job.
Ampix0 #3
Posted 12 May 2013 - 11:03 PM
This is good for a beginner, good job.
being as experienced as you are, could I bother you for some peer review? the height tracking doesn't work, it looks like its because if the turtle moves down and there is a blog it should enter an if statement which makes it dig, and try again. It seems like the counter goes up or down on each loop even if it goes into the if statement (which should cause it to never see the add/subtract code on the first pass).
unobtanium #4
Posted 13 May 2013 - 05:04 AM
What about adding some functions for the movement commands, in which the turtle moves the amount of blocks depending on how far it should move.
smartMoveForward(10)
Because myself is making functions like


function smartMoveForward(x)
for i=1,x do
while not turtle.forward() do turtle.dig() sleep(1) end
end
end


Allready knowing where CC and turtles have their problems and limits is allways good to know ;D
Ampix0 #5
Posted 13 May 2013 - 10:11 AM
I will absolutely upgrade the smart movements to do that. I'll add that in asap
Ampix0 #6
Posted 14 May 2013 - 11:16 PM
Updated to 2.0 code was completely rewritten from scratch. Now FAR more efficient, shorter, and does more.
CamShirayuki #7
Posted 14 May 2013 - 11:50 PM
Ampix, good sir, I love this. But, you should really move this to the OS section of this website. ^o^
Ampix0 #8
Posted 15 May 2013 - 12:15 AM
Ampix, good sir, I love this. But, you should really move this to the OS section of this website. ^o^
It isn't REALLY an OS, it's just a startup program for the turtle, It offers no normal OS functions it is really more of an API, I am just calling it an OS. If the mods think is.. qualifies as an actual OS somehow they can move it lol.
GalaxyMaster #9
Posted 16 May 2013 - 11:58 AM
Looks very useful, will definitely try this!
unobtanium #10
Posted 16 May 2013 - 12:12 PM
Just looked in he code real quick. At line 39 you still have the wrong version number standing: print("SmartTurtleOS
1.0")
Quick question: If i definite these functions on the start of the turtle, i can use them in any program i write? (I know that i have to use the turtle with this program as startup then^^) Because i may get into this stuff as well. I am really getting annoyed to add the same functions in my programs over and over again…

Just a quick tip: Instead of writing if turtle.detect() == false then you can write if not turtle.detect() then
It makes it short, but more visual as well.
Ampix0 #11
Posted 17 May 2013 - 01:00 AM
Just looked in he code real quick. At line 39 you still have the wrong version number standing: print("SmartTurtleOS
1.0")
Quick question: If i definite these functions on the start of the turtle, i can use them in any program i write? (I know that i have to use the turtle with this program as startup then^^) Because i may get into this stuff as well. I am really getting annoyed to add the same functions in my programs over and over again…

Just a quick tip: Instead of writing if turtle.detect() == false then you can write if not turtle.detect() then
It makes it short, but more visual as well.

Thanks for the catch! And thanks for the coding tip, I'll fix both in my next update.

And yes. If the user runs this as their startup file you can use the functions. So instead of writing

turtle.dig()
turtle.forward()

however many times (or looping it), You may simply write

smartMoveForward(x)

and it will check fuel, dig and move forward with persistence.
Spongy141 #12
Posted 19 May 2013 - 11:38 PM
I do not like this, this isn't a real OS… Things like this bugs me, why not just make it an API [The type you call with os.loadAPI()]? That would be a smart thing to do.
Ampix0 #13
Posted 22 May 2013 - 12:39 PM
I do not like this, this isn't a real OS… Things like this bugs me, why not just make it an API [The type you call with os.loadAPI()]? That would be a smart thing to do.

Why is this any smarter?As far as I can really see this presents no down side and less typing.
unobtanium #14
Posted 22 May 2013 - 12:42 PM
Then you could have an other program as startup… that what is the negative aspect of your program. Your program should let the turtle set a startup-program variable and after it runs your OS it checks if the variable is set, and then starts the program.
Spongy141 #15
Posted 22 May 2013 - 07:01 PM
I do not like this, this isn't a real OS… Things like this bugs me, why not just make it an API [The type you call with os.loadAPI()]? That would be a smart thing to do.

Why is this any smarter?As far as I can really see this presents no down side and less typing.
First, if this was a real OS it would be in the OS section, since it is just an API, you should just have it be an API, when I said I do not like this I meant how you call it something it is not, I think it's a nice API, but I would rather use it if it were an API (Calling it with os.loadAPI()) instead of a startup program. It would make more sense to do that. OR just release both, anyways, like I said, it seems cool, and I will probably use it if you were to call it by its correct name.
Ampix0 #16
Posted 23 May 2013 - 12:35 AM
I do not like this, this isn't a real OS… Things like this bugs me, why not just make it an API [The type you call with os.loadAPI()]? That would be a smart thing to do.

Why is this any smarter?As far as I can really see this presents no down side and less typing.
First, if this was a real OS it would be in the OS section, since it is just an API, you should just have it be an API, when I said I do not like this I meant how you call it something it is not, I think it's a nice API, but I would rather use it if it were an API (Calling it with os.loadAPI()) instead of a startup program. It would make more sense to do that. OR just release both, anyways, like I said, it seems cool, and I will probably use it if you were to call it by its correct name.

I'll take the next update to the API section.
Spongy141 #17
Posted 23 May 2013 - 09:21 AM
-snip-
You can just click 'report' and ask to have your topic be moved.
Zudo #18
Posted 23 May 2013 - 11:18 AM
This is good for a beginner, good job.

I totally agree!
Engineer #19
Posted 01 June 2013 - 04:33 AM
Since these are functions, you can place tgmhis in the startup folder and just type your own startup program at the very bottom..

I kind of like this, but only one thing bugs me: the name. I dont want to type smartMoveForward(5).. I would suggest to change to shorter names, eg. smartForward(5)..

This looks very promising though!