Jump to content




eltrut API [Movement|Inventory|On-Screen]


7 replies to this topic

#1 unobtanium

  • Members
  • 505 posts

Posted 01 June 2013 - 07:07 AM

Hello everybody,

i made quite a lot of programs for CC and the turtles right now and i allways came over some functions i created, because the allready build-in ones weren't enough. That's why i created a little api, more for myself, which i am going over in this post.
Why "eltrut"? Well, i am working most of my time with turtles and if you mirror "turtle" you get "eltrut" :D


ELTRUT 0.1.0

Pastebin

9MKEWafV


Commands


Screen

clearScreen()
This is going to clear the screen completely an sets the Cursor at 1|1

clearLine( int line )
Clears the selected line on the screen.

clearColumn( int column )
Clears the selected column on the screen.

clearColumn( int column, int startLine, int endLine )
Clears the given column from a given line down to another given line.

centerCursor( int line )
Sets the cursor position in the middle of the screen line.

leftCursor( int line )
Sets the cursor position on the left side of the screen at the given line.

rightCursor( int line )
Sets the cursor position on the right side of the screen at the give line.


Print

print( string text, int line, int column)
Prints the given text at the given position on the screen.

printCentered( string text, int line )
Prints the given text centered in the given line on the screen.

printCenteredR( string text, int line )
Clears the line and writes the given text centered at the given line.
"R" stands for Replace.

printRight( string text, int line )
Prints the text on the right side of the screen.

printRightR( string text, int line )
Clears the line and writes the given text on the right side of the screen at the given line.

printLeft( string text, int line )
Prints the text on the left side of the screen.

printLeftR( string text, int line )
Clears the line and writes the given text on the right side of the screen at the given line.

printVertical( string text, int column )
Prints letter for letter the text in the given column.

printVerticalR( string text, int column )
Clears the column and prints letter for letter the text at the given column.

printHeader( string text, int line )
Prints the text centered at the given line and one below a line with "-"


Fuel

refuel( int slot, int level)
Refuels the turtle from the given slot until it has the same or more fuel level.


Inventory

countInventory()
Counts all 16 slots in the inventory and returns the amount.


countSlots( int firstSlot, int lastSlot )
Counts all slots from the first given slot to the last given slot.
Returns the amount of items in these slots.

compareToSlots( int selectedSlot, int firstSlot, int lastSlot )
Compares the selected slot to the other given slots.
Returns false if one of the slots hasnt the same kind of item in it.

transferTo( int firstSlot, int secondSlot, [ int quantity ])
Transfers the first given slot to the second given slot by the amount given.

transferToSlots( int startSlot, int lastSlot, int toSlot )
Transfers all slots from startSlot to lastSlot to toSlot and the following slots.


drop( int slot, [ int quantity ])
Drops the items in the given slot in the front of the turtle.

dropUp( int slot, [ int quantity ])
Drops the items in the given slot up.

dropDown( int slot, [ int quantity ])
Drops the items in the given slot down.

dropSlots( int startSlot, int endSlot )
Drops all items from the given startSlot to the last slot given by endSlot in front of the turtle.
Returns true if all slots are dropped; false if there are slots still left.

dropSlotsUp( int startSlot, int endSlot )
Drops all items from the given startSlot to the last slot given by endSlot up.
Returns true if all slots are dropped; false if there are slots still left.

dropSlotsDown( int startSlot, int endSlot )
Drops all items from the given startSlot to the last slot given by endSlot down.
Returns true if all slots are dropped; false if there are slots still left.

dropSameTo( int slot )
Drops all items which are the same like in the given slot. Doesn't drop the given slot!
Returns the amount of items dropped in front of the turtle.

dropUpSameTo( int slot )
Drops all items which are the same like in the given slot. Doesn't drop the given slot!
Returns the amount of items dropped up.

dropDownSameTo( int slot )
Drops all items which are the same like in the given slot. Doesn't drop the given slot!
Returns the amount of items dropped down.



suck( int slot )
Sucks items in the front of the turtle into the given slot and returns the amount of items in this slot.

suckUp( int slot )
Sucks items from above into the given slot and returns the amount of items in this slot.


suckDown( int slot )
Sucks items from underneath into the given slot and returns the amount of items in this slot.

suckSlots( int startSlot, int endSlot )
Sucks items into the given slots if there arent items in them allready.
Returns the amount of items in the slots.

suckSlotsUp( int startSlot, int endSlot )
Sucks items into the given slots if there arent items in them allready.
Returns the amount of items in the slots.

suckSlotsDown( int startSlot, int endSlot )
Sucks items into the given slots if there arent items in them allready.
Returns the amount of items in the slots.

Dig

dig()
Digs the block in front if the turtle detects one. Keeps going until no blocks are left.


digDown()
Digs the block below if the turtle detects one. Keeps going until no blocks are left.

digUp()
Digs the block above if the turtle detects one. Keeps going until no blocks are left.



Movement

turnAround()
Turns the turtle two times left or two times right to face into the other direction.

forward( [ int length ] )
Moves forward or waits if something is in front of it.

forwardDig( [ int length ] )
Moves forward and digs if something is in the way.

forwardExtreme( [ int length ] )
Moves forward and digs or attacks if something is in front of it.

back( [ int length ] )
Moves backwards or waits if something is blocking it.

backDig( [ int length ] )
Moves backwards and turns around to dig if something is in the way.

backExtreme( [ int length ] )
Moves backwards and digs or attacks if something is in the way.

up( [ int length ] )
Moves up or waits if something is blocking it.

upDig( [ int length ] )
Moves up and digs if something is in the way.

upExtreme( [ int length ] )
Moves up and digs or attacks if something is in the way.

down( [ int length ] )
Moves down or waits if something is blocking it.

downDig( [ int length ] )
Moves down and digs if something is in the way.

downExtreme( [ int length ] )
Moves down and digs or attacks if something is in the way.



I am probably adding more to this api over time. So if you want to see something in it feel free to tell me :D
Thank you for your attention.
Special thanks goes to AxxiD or testing and debugging.
unobtanium

#2 computercraftprogrammer

  • Members
  • 122 posts
  • Location$house->Earth->MilkyWay->Universe;

Posted 14 June 2013 - 01:34 PM

Nice work!

#3 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 26 June 2013 - 01:13 AM

Great as always!

#4 MarrusQ

  • New Members
  • 2 posts

Posted 04 July 2013 - 07:21 AM

This is mindblowing! (somewhat) The only thing that was missing to complete my excessive turtle stripmining project! With a little bit of rewriting (mostly clearing up code) they should be able to mine and process (TBD) all those precious ores by the time of saturday (instead of tuesday). Thanks man!

Sincerely
Marrus with a Q

#5 unobtanium

  • Members
  • 505 posts

Posted 04 July 2013 - 07:52 AM

Thanks guys. Nice to hear that you like it :)

#6 Galactica4

  • Members
  • 44 posts
  • LocationAustralia

Posted 14 July 2013 - 01:07 AM

Cooool

#7 AxxiD

  • New Members
  • 1 posts
  • LocationGermany

Posted 25 October 2013 - 09:44 AM

While trying your API a bunch of errors came up like missing some 'end' and having 'end' as a variable which does not work!
So i gave it two minutes to correct them all ;)
Here is the fixed version: http://pastebin.com/B3JRwj8s

Btw: Pretty nice work! :)

EDIT: While testing more and more errors come up. I'll will post here when done editing and testing.
EDIT 2: I just have gone through the utils from the sections "SCREEN" and "PRINT". The fixxed version can be found on the link provided above :)

#8 unobtanium

  • Members
  • 505 posts

Posted 25 October 2013 - 04:14 PM

Thanks dude! I replaced my code with yours and metioned you in the code as well :)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users