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

Turtle Commands

Started by Cherrie, 14 April 2012 - 09:50 PM
Cherrie #1
Posted 14 April 2012 - 11:50 PM
Hi, I've been around for a couple of days now reading this and that topic, and there seems to be this knowledge shared between members here that keeps slipping away from me, so I came here to ask this : Where can I find the full turtle command list? I'd like to know if a library of its functions exists in the CC mod , v1.3 I downloaded. If not, a link to a thread on the forums would do. (searched already, but couldn't find that exact thing…)

Specifications: I opened all the files in the 'turtle' folder, they all seem to use commands like "turtle.<something>", so what I'm looking for is a list of the <somethings> that I can use. I may also need to create some functions myself, so I'm looking for the source of those commands that are translated to the language the turtle understands, but since my knowledge of programming is quite limited, and I never encountered Lua before, your help will be highly appreciated.
p.s - I guess this is a newb question, so if you don't feel like handing out the answer, hints and directions to the answer will be just as good, I like finding things myself rather than having them handed to me ^~^

Cheers.
Luanub #2
Posted 14 April 2012 - 11:54 PM
Goto the wiki and then the apis section, It list each api and from there a list of the commands available for the api.

Turtle is here

You can also type help turtle from a terminal in the game
MysticT #3
Posted 14 April 2012 - 11:58 PM
Try searching on the wiki, there's a full list of every api functions (like the turtle api), or look at the in-game help (help turtle). The sources for the turtle api are not available, since it's coded in the mod (in java), so you have to use the api to create your own functions.
Cherrie #4
Posted 14 April 2012 - 11:59 PM
So THAT is what API's are… gee thanks for the quick response mate :)/>/>)
Ninjawolf0007 #5
Posted 01 April 2013 - 10:58 AM
Here is the most up to date list: Please note, not every API function is listed here.
SpoilercommandBlock.getCommand( ) Returns a string containing the command currently inside the Command Block. commandBlock.setCommand( string command ) Sets the command in the Command Block. This does not run it. commandBlock.runCommand( )
Runs the command inside the Command Block previously set by commandBlock.setCommand( )
Method name Description computer.turnOn() Turns on the Computer or Turtle. computer.shutdown() Shuts off the Computer or Turtle. computer.reboot() Reboots the Computer or Turtle. computer.getID() Gets the ID of the Computer or Turtle. Bit (API) Method name Description bit.tobits(int n) Converts a number to an array (numerically-indexed table) containing the corresponding binary bit values. bit.blshift(int n, int bits) Shifts a number left by a specified number of bits. bit.brshift(int n, int bits) Shifts a number right by a specified number of bits. bit.bxor(int m, int n) Computes the bitwise exclusive OR of two numbers. bit.bor(int m, int n) Computes the bitwise inclusive OR of two numbers. bit.band(int m, int n) Computes the bitwise AND of two numbers. bit.bnot(int n) Computes the bitwise NOT of a number. bit.tonumb(table bit_tbl) Converts an array (numerically-indexed table) of 0 and 1 values representing a number in binary into that number.
Printer (API) printer.getPaperLevel() Returns the amount of paper available in the paper tray. printer.newPage() Starts a new page. Returns true if page got started, false if not. printer.endPage() Ends the page and prints the page to the output tray. Returns true if page was ended, false if not. printer.write(string text) Writes text to the paper, works the same way as term.write() printer.setPageTitle(string title) Sets the title of the page. printer.getInkLevel() Returns the amount of ink in the ink slot. printer.getCursorPos() Returns the coordinates of the cursor on the paper, works the same way as term.getCursorPos() printer.setCursorPos(int x, int y) Sets the cursor pos, works the same way as term.setCursorPos() printer.getPageSize() Returns the size of the paper, works the same way as term.getSize()

colors (API) Method Name Description colors.combine(color1, color2, …) Combines a set of colors (or sets of colors) into a larger set. colors.subtract(colors, color1, color2, …) Removes one or more colors (or sets of colors) from an initial set. colors.test(colors, color) Tests whether a given color (or set of colors) is contained within a set.

Coroutine (API) Method Name Description coroutine.create(function) Creates and Returns a new coroutine. coroutine.resume(coroutine, [var1], [var2], …) Starts or Resumes an already-made coroutine. coroutine.running() Returns the coroutine running (nil if it's the main coroutine). coroutine.status(coroutine) Returns the status of the given coroutine. coroutine.wrap(function) Creates and Returns a new coroutine in the form of a function. coroutine.yield([var1], [var2], …) Pauses the coroutine. Variables passed will be extra variables next time the coroutine starts.

Disk (API) Method Name Description disk.isPresent(string side ) Checks the given side for a disk disk.hasData(string side ) Checks whether the current disk is a floppy disk, as opposed to a music disk. disk.getMountPath(string side ) Returns the directory path on which the disk on side has been mount (ex. /disk) disk.setLabel(string side, string label ) Sets the label disk.getLabel(string side ) Finds label disk.getDiskID(string side ) Finds ID (unique for every disk) disk.hasAudio(string side ) Checks whether the current disk is a music disk, as opposed to a floppy disk. disk.getAudioTitle(string side ) Returns the audio title on the disk disk.playAudio(string side ) Plays the audio disk.stopAudio(string side ) Stops the audio disk.eject(string side ) Ejects the disk.

Fs (API) Method Name Description fs.list(path) Lists the directories and files in the given directory fs.exists(path) Checks if a path refers to an existing file or directory fs.isDir(path) Checks if a path refers to an existing directory fs.isReadOnly(path) Checks if a path is read-only (i.e. cannot be modified) fs.getName(path) Gets the final component of a pathname fs.getDrive(path) Gets the type of storage medium holding a file or directory fs.getSize(path) Gets the size of a file and returns in bytes fs.getFreeSpace(path) Gets the remaining space in the given directory. fs.makeDir(path) Makes a directory fs.move(fromPath, toPath) Moves a file or directory to a new location fs.copy(fromPath, toPath) Copies a file or directory to a new location fs.delete(path) Deletes a file or directory fs.combine(basePath, localPath) Combines two path components, returning a path consisting of the local path nested inside the base path fs.open(path, mode) Opens a file so it can be read or written

Gps (API) Method Name Description gps.locate(timeout, debug) Tries to retrieve the computer or turtles own location.

@param timeout the amount of time, in seconds, to wait for a rednet response
@param debug if true, outputs debug messages @return the location (x, y, z) of the modem attached to the computer or turtle or nil if it could not be determined

Help (API) Method Name Description help.path() Returns the path the help API has been set to help.setPath(string path) Sets the path of the API to path help.lookup(string topic) Looks up the help file for topic help.topics() Returns a table of valid help topics

HTTP (API) Method Name Description http.request( url, *postData ) Sends a HTTP request to a website. http.get( url ) Sends a HTTP GET request to a website. http.post( url, postData ) Sends a HTTP POST request to a website.
Modem API Function Description isOpen( int channel ) Check to see if the specified channel is open open( int channel ) Opens the specified channel to allow for listening. The channel specified must be larger than 0 and less than 65535. close( int channel ) Closes an open channel to disallow listening closeAll( ) Closes all open channels transmit( int channel, intreplyChannel, string message ) Transmits a message on the specified channel isWireless( ) Returns true if the modem is wireless; false if it is wired.

OS (API) Method Name Description os.version() Returns the version of the OS the computer is running. os.getComputerID() Returns the unique ID of this computer. os.computerID() also behaves exactly the same as os.getComputerID(). os.getComputerLabel() Returns the label of this computer. os.setComputerLabel( label ) Set the label of this computer. os.run( environment, programpath, arguments ) An advanced way of starting programs. A started program will have a given environment table which determines what functions it has available, as well as any variables it will be able to access by default. You may prefer to use the Shell (API) unless you need to do something special. os.loadAPI( name ) Loads a Lua script as an API in it's own namespace (see example). It will be available to all programs that run on the terminal. os.unloadAPI( name ) Unloads a previously loaded API. os.pullEvent( target-event ) Blocks until the computer receives an event, or if target-event is specified, will block until an instance of target-event occurs. os.pullEvent( target-event ) returns the event and any parameters the event may have. If a target-event is specified, the computer will not break for any other events (except termination). os.pullEventRaw() Advanced version of pullEvent(). os.pullEventRaw() will block until an event occurs, and then returns the event (any any parameters the event may have). Unlike os.pullEvent( target-event ), this function will not break for system events, and can be used to handle termination events. os.queueEvent( event, param1, param2, … ) Adds an event to the event queue with the name event and the given parameters os.clock() Returns CPU time. os.startTimer( timeout ) Queues an event to be triggered after a number of seconds (timeout). The ID of the timer is returned from this function to differentiate multiple timers. Timers are one-shot; once they have fired an event you will need to start another one if you need a recurring timer. os.sleep( timeout ) Makes the system wait a number of seconds before continuing in the program. os.sleep( timeout ) may also be used as simply "sleep( timeout )". os.time() Returns the current Minecraft world time. os.day() Returns the current Minecraft day. os.setAlarm( time ) Queues an event to be triggered at the specified Minecraft world time. os.shutdown() Turns off the computer. os.reboot() Reboots the computer.

Paintutils (API) Method Name Description paintutils.loadImage(path) Returns an image object. paintutils.drawImage(image, x, y) Draws an image at (x, y) where image is an image object. paintutils.drawPixel(x, y, colour) Draws a pixel at (x, y) in the colour specified. paintutils.drawLine(startX, startY, endX, endY, colour) Draws a line from (startX, startY) to (endX, endY) in the colour specified.

Parallel (API) Method Name Description parallel.waitForAny(function1, function2, …) Runs all the functions at the same time, and stops when any of them returns. parallel.waitForAll(function1, function2, …) Runs all the functions at the same time, and stops when all of them have returned.

Peripheral (API) Method Name Description peripheral.isPresent(side) Returns true if a peripheral is present on side. peripheral.getType(side) Returns the type or peripheral present on side, nothing returned if side is empty. peripheral.getMethods(side) Returns a table containing all methods for peripheral on side. peripheral.call(side, methodName, param1, param2, …) Sends a function call to peripheral located on side. Return values match those of called method.
Note: methodName is a string. peripheral.wrap(side) Returns a handle to the peripheral located on side. If assigned to a variable, it can be used to call all methods available from that peripheral, as if calling peripheral.call(), e.g.:
m = peripheral.wrap("left")
m.someMethod()
- is the same as -
peripheral.call("left","someMethod")

Rednet (API) Method Name Description rednet.open(side) Tells the computer that the side can be used for networking. rednet.close(side) Tells the computer that the side can no longer be used for networking. rednet.announce() Broadcasts an empty rednet message. rednet.send(receiverID, message) Sends a message to the computer using the opened sides. The receiver ID is the ID (number, not string) of the computer you're sending the message to. ID as nil will do the same as a broadcast. The message must be a string to send across rednet, if you are wanting to send a table see textutils.serialize rednet.broadcast(message) Sends the message to ALL connected and open computers. rednet.receive(timeout) Waits until it received a rednet message or timeout has passed. Leave args empty to wait for a message forever. rednet.isOpen(side) Returns true if the wireless modem is open.

Redstone (API) Method Name Description redstone.getSides() Returns an array of possible sides redstone.getInput(string side) Returns the current redstone input signal state on side redstone.setOutput(string side, boolean value) Set or reset a redstone signal on side redstone.getOutput(string side) Returns the current redstone output signal on side redstone.getBundledInput(string side) Returns the state of a redpower wire inside a bundle connected to side redstone.getBundledOutput(string side) Returns the set of redpower wires inside a bundle on side that are being driven high by the local console (not those that are driven high by another device on the bundle but not driven high by the local console) redstone.setBundledOutput(string side, int colors) Sets one or multiple colored signals in a redpower bundled wire connected to Side. In order to set multiple signals, add the color values of the colors you want to activate. To turn off all of the values, use 0 for the integer. redstone.testBundledInput(string side, int color) Returns true or false whether or not a colored signal is active in a redpower bundled wire connected to Side

Shell (API) Method Name Description shell.exit() Exits the current shell shell.dir() Returns the directory shell.setDir(path) Sets the directory shell.path() Returns the path shell.setPath(path) Sets the path shell.resolve(localpath) Resolves a local path to an absolute path. shell.resolveProgram(name) Resolves the absolute path to the program whose name you provided. shell.aliases() Returns aliases. shell.setAlias(alias, command) Sets an alias. shell.clearAlias(alias, command) Clears an alias. shell.programs() Returns programs. shell.run(program, arguments) Runs a program. shell.getRunningProgram() Returns the absolute path to the currently-executing program.
Term (API) Method Name Description term.write(text) Writes text to the screen. term.clear() Clears the entire screen term.clearLine() Clears the line the cursor is on term.getCursorPos() Returns two arguments containing the x and the y position of the cursor. term.setCursorPos(x, y) Sets the cursor's position. term.setCursorBlink(bool) Disables the blinking or turns it on. term.isColor() Returns if the computer supports color. (Used to determine whether or not an Advanced Computer is being used) term.getSize() Returns two arguments containing the x and the y values stating the size of the screen. (Good for if you're making something to be compatible with both Turtles and Computers.) term.scroll(n) Scrolls the terminal n lines. term.redirect(target) Redirects terminal output to a monitor or other redirect target. (Use peripheral.wrap to acquire a monitor "object".) term.restore() Restores terminal output to the previous target. term.setTextColor(color) Sets the text-color of the terminal. Available only to Advanced Computers and Advanced Monitors. term.setBackgroundColor(color) Sets the background color of the terminal. Available only to Advanced Computers and Advanced Monitors.

Textutils (API) Method Name Description textutils.slowPrint(string text, int rate) Slowly prints the text. Only difference is, it leaves a new-line after it. textutils.slowWrite(string text, int rate) Slowly writes the text. textutils.formatTime(int time, bool TwentyFourHour) Put a time into it, and it spews it out in a different format. Example: print(textutils.formatTime(os.time(), false)) textutils.tabulate(table table, table table2, …) Prints tables in an ordered form. Each table is a row, columns' width is auto-adjusted. textutils.pagedTabulate(table table, table table2, …) A description is required. textutils.pagedPrint(string string, string confirmation_lines) Prints a string onto the screen, but waits for confirmation before scrolling down. textutils.serialize(table table) Returns a string representation of the table t for storage or transmission. textutils.unserialize(string text) Returns a table reassembled from the string s. textutils.urlEncode(string text) Makes a string safe to encode into a url. Spaces are replaced with +s. Unsafe characters such as '\', '£' and '}' are translated into ASCII code and preceded with a % for transmission. For reference visit: [1].

Turtle (API)




The Turtle API is used to work with your Turtles.
Key
Color Turtles that can perform this White All Green Crafty Yellow Mining, Felling, Digging, Farming Red Any tool
API
Return Method name Description Min version bool success turtle.craft( quantity ) Craft items using ingredients anywhere in the Turtle's inventory and place results in the active slot. If a quantity is specified, it will craft only up to that many items, otherwise, it will craft as many of the items as possible. bool success turtle.forward() Let the Turtle move forward bool success turtle.back() Let the Turtle move back bool success turtle.up() Let the Turtle move up bool success turtle.down() Let the Turtle move down bool success turtle.turnLeft() Let the Turtle turn left bool success turtle.turnRight() Let the Turtle turn right bool success turtle.select(slotNum) The Turtle selects the given Slot (1 is top left, 16 (9 in 1.33 and earlier) is bottom right) int result turtle.getItemCount(slotNum) Counts how many items are in the given Slot int result turtle.getItemSpace(slotNum) Counts how many remaining items you need to fill the stack in the given Slot bool success turtle.attack() Attacks in front of the turtle. 1.4 bool success turtle.attackUp() Attacks over the turtle. 1.4 bool success turtle.attackDown() Attacks under the turtle. 1.4 bool success turtle.dig() Breaks the Block in front. With hoe: tills the dirt in front of it. bool success turtle.digUp() Breaks the Block above. With hoe: tills the dirt above it. bool success turtle.digDown() Breaks the Block below. With hoe: tills the dirt below it. bool success turtle.place(signText) Places a Block of the selected slot in front. Engrave signText on signs if provided. 1.4 bool success turtle.placeUp() Places a Block of the selected slot above bool success turtle.placeDown() Places a Block of the selected slot below bool result turtle.detect() Detects if there is a Block in front. Does not detect mobs. bool result turtle.detectUp() Detects if there is a Block above bool result turtle.detectDown() Detects if there is a Block below bool result turtle.compare() Detects if the block in front is the same as the one in the currently selected slot bool result turtle.compareUp() Detects if the block above is the same as the one in the currently selected slot bool result turtle.compareDown() Detects if the block below is the same as the one in the currently selected slot bool result turtle.compareTo(slot) Compare the current selected slot and the given slot to see if the items are the same, yields true if they are the same, and false if not. 1.4 bool success turtle.drop(count) Drops all items in the selected slot, or if count is specified, drops that many items.
[>= 1.4 only:] If there is a inventory on the side (i.e in front of the turtle) it will try to place into the inventory, returning false if the inventory is full. bool success turtle.dropUp(count) Drops all items in the selected slot, or if count is specified, drops that many items.
[>= 1.4 only:] If there is a inventory on the side (i.e above the turtle) it will try to place into the inventory, returning false if the inventory is full. If below a furnace, will place item in the bottom slot. bool success turtle.dropDown(count) Drops all items in the selected slot, or if count is specified, drops that many items.
[>= 1.4 only:] If there is a inventory on the side (i.e below the turtle) it will try to place into the inventory, returning false if the inventory is full. If above a furnace, will place item in the top slot. bool success turtle.suck() Picks up an item stack of any number, from the ground or an inventory in front of the turtle. If the turtle can't pick up the item, the function yields false. 1.4 bool success turtle.suckUp() Picks up an item stack of any number, from the ground or an inventory above the turtle. If the turtle can't pick up the item, the function yields false. 1.4 bool success turtle.suckDown() Picks up an item stack of any number, from the ground or an inventory below the turtle. If the turtle can't pick up the item, the function yields false. 1.4 bool success turtle.refuel(quantity) If the current selected slot contains a fuel item, it will consume it to give the turtle the ability to move.
Added in 1.4 and is only needed in needfuel mode. If the current slot doesn't contain a fuel item, it yields false. Fuel values for different items can be found atTurtle.refuel#Fuel_Values. If a quantity is specified, it will refuel only up to that many items, otherwise, it will consume all the items in the slot. 1.4 int fuel turtle.getFuelLevel() Returns the current fuel level of the turtle, this is the number of blocks the turtle can move.
If turtleNeedFuel = 0 then it yields "unlimited". 1.4 bool success turtle.transferTo(slot, quantity) Transfers items from the selected slot to the specified slot in the [quantity] inputted. 1.45


Vector (API) Method Name Description vector.new(float x, float y, float z) Creates a vector. vectorA:add(vector vectorB) Adds vectorB to vectorA and returns the resulting vector. Can also be used by writing vectorA + vectorB. vectorA:sub(vector vectorB) Subtracts vectorB from vectorA and returns the resulting vector. Can also be used by writing vectorA - vectorB. vectorA:mul(float n) Scalar multiplies vectorA with n and returns the resulting vector. Can also be used by writing vectorA * n. vectorA:dot(vector vectorB) Returns the dot product of vectorA and vectorB. vectorA:cross(vector vectorB) Returns the vector which resulted in the cross product of vectorA and vectorB. vectorA:length() Returns the vector's length. vectorA:normalize() Normalizes the vector and returns the result as a new vector. vectorA:round() Rounds the vector coordinates to the nearest integers and returns the result as a new vector. vectorA:tostring() Returns a string representation of the vector in the form of "x,y,z".
GeniusChild #6
Posted 27 May 2013 - 02:33 PM
It wont let me make a post. Anyone know why?
Bomb Bloke #7
Posted 28 May 2013 - 07:28 AM
http://www.computercraft.info/forums2/index.php?/topic/9919-new-members-needing-to-ask-questions-please-read/