turtle

The turtle API allows you to control your turtle.

forward()Move the turtle forward one block.
back()Move the turtle backwards one block.
up()Move the turtle up one block.
down()Move the turtle down one block.
turnLeft()Rotate the turtle 90 degress to the left.
turnRight()Rotate the turtle 90 degress to the right.
dig([side])Attempt to break the block in front of the turtle.
digUp([side])Attempt to break the block above the turtle.
digDown([side])Attempt to break the block below the turtle.
place([text])Place a block or item into the world in front of the turtle.
placeUp([text])Place a block or item into the world above the turtle.
placeDown([text])Place a block or item into the world below the turtle.
drop([count])Drop the currently selected stack into the inventory in front of the turtle, or as an item into the world if there is no inventory.
dropUp([count])Drop the currently selected stack into the inventory above the turtle, or as an item into the world if there is no inventory.
dropDown([count])Drop the currently selected stack into the inventory in front of the turtle, or as an item into the world if there is no inventory.
select(slot)Change the currently selected slot.
getItemCount([slot])Get the number of items in the given slot.
getItemSpace([slot])Get the remaining number of items which may be stored in this stack.
detect()Check if there is a solid block in front of the turtle.
detectUp()Check if there is a solid block above the turtle.
detectDown()Check if there is a solid block below the turtle.
compare()
compareUp()
compareDown()
attack([side])Attack the entity in front of the turtle.
attackUp([side])Attack the entity above the turtle.
attackDown([side])Attack the entity below the turtle.
suck([count])Suck an item from the inventory in front of the turtle, or from an item floating in the world.
suckUp([count])Suck an item from the inventory above the turtle, or from an item floating in the world.
suckDown([count])Suck an item from the inventory below the turtle, or from an item floating in the world.
getFuelLevel()
refuel([countA])
compareTo(slot)
transferTo(slotArg[, countArg])
getSelectedSlot()Get the currently sleected slot.
getFuelLimit()
equipLeft()
equipRight()
inspect()
inspectUp()
inspectDown()
getItemDetail([slot[, detailed]])Get detailed information about the items in the given slot.
craft(limit)
nativeThe builtin turtle API, without any generated helper functions.
forward()Source

Move the turtle forward one block.

Returns

  1. boolean Whether the turtle could successfully move.
  2. string | nil The reason the turtle could not move.
back()Source

Move the turtle backwards one block.

Returns

  1. boolean Whether the turtle could successfully move.
  2. string | nil The reason the turtle could not move.
up()Source

Move the turtle up one block.

Returns

  1. boolean Whether the turtle could successfully move.
  2. string | nil The reason the turtle could not move.
down()Source

Move the turtle down one block.

Returns

  1. boolean Whether the turtle could successfully move.
  2. string | nil The reason the turtle could not move.
turnLeft()Source

Rotate the turtle 90 degress to the left.

Returns

  1. any... The turtle command result.
turnRight()Source

Rotate the turtle 90 degress to the right.

Returns

  1. any... The turtle command result.
dig([side])Source

Attempt to break the block in front of the turtle.

This requires a turtle tool capable of breaking the block. Diamond pickaxes (mining turtles) can break any vanilla block, but other tools (such as axes) are more limited.

Parameters

  1. side? string The specific tool to use. Should be "left" or "right".

Returns

  1. boolean Whether a block was broken.
  2. string | nil The reason no block was broken.
digUp([side])Source

Attempt to break the block above the turtle. See dig for full details.

Parameters

  1. side? string The specific tool to use.

Returns

  1. boolean Whether a block was broken.
  2. string | nil The reason no block was broken.
digDown([side])Source

Attempt to break the block below the turtle. See dig for full details.

Parameters

  1. side? string The specific tool to use.

Returns

  1. boolean Whether a block was broken.
  2. string | nil The reason no block was broken.
place([text])Source

Place a block or item into the world in front of the turtle.

Parameters

  1. text? string When placing a sign, set its contents to this text.

Returns

  1. boolean Whether the block could be placed.
  2. string | nil The reason the block was not placed.
placeUp([text])Source

Place a block or item into the world above the turtle.

Parameters

  1. text? string When placing a sign, set its contents to this text.

Returns

  1. boolean Whether the block could be placed.
  2. string | nil The reason the block was not placed.
placeDown([text])Source

Place a block or item into the world below the turtle.

Parameters

  1. text? string When placing a sign, set its contents to this text.

Returns

  1. boolean Whether the block could be placed.
  2. string | nil The reason the block was not placed.
drop([count])Source

Drop the currently selected stack into the inventory in front of the turtle, or as an item into the world if there is no inventory.

Parameters

  1. count? number The number of items to drop. If not given, the entire stack will be dropped.

Returns

  1. boolean Whether items were dropped.
  2. string | nil The reason the no items were dropped.

Throws

  • If dropping an invalid number of items.

See also

dropUp([count])Source

Drop the currently selected stack into the inventory above the turtle, or as an item into the world if there is no inventory.

Parameters

  1. count? number The number of items to drop. If not given, the entire stack will be dropped.

Returns

  1. boolean Whether items were dropped.
  2. string | nil The reason the no items were dropped.

Throws

  • If dropping an invalid number of items.

See also

dropDown([count])Source

Drop the currently selected stack into the inventory in front of the turtle, or as an item into the world if there is no inventory.

Parameters

  1. count? number The number of items to drop. If not given, the entire stack will be dropped.

Returns

  1. boolean Whether items were dropped.
  2. string | nil The reason the no items were dropped.

Throws

  • If dropping an invalid number of items.

See also

select(slot)Source

Change the currently selected slot.

The selected slot is determines what slot actions like drop or getItemCount act on.

Parameters

  1. slot number The slot to select.

Returns

  1. any... The turtle command result.

Throws

  • If the slot is out of range.

See also

getItemCount([slot])Source

Get the number of items in the given slot.

Parameters

  1. slot? number The slot we wish to check. Defaults to the selected slot.

Returns

  1. number The number of items in this slot.

Throws

  • If the slot is out of range.

getItemSpace([slot])Source

Get the remaining number of items which may be stored in this stack.

For instance, if a slot contains 13 blocks of dirt, it has room for another 51.

Parameters

  1. slot? number The slot we wish to check. Defaults to the selected slot.

Returns

  1. number The space left in in this slot.

Throws

  • If the slot is out of range.

detect()Source

Check if there is a solid block in front of the turtle. In this case, solid refers to any non-air or liquid block.

Returns

  1. boolean If there is a solid block in front.
detectUp()Source

Check if there is a solid block above the turtle. In this case, solid refers to any non-air or liquid block.

Returns

  1. boolean If there is a solid block in front.
detectDown()Source

Check if there is a solid block below the turtle. In this case, solid refers to any non-air or liquid block.

Returns

  1. boolean If there is a solid block in front.
compare()Source

Returns

  1. any...
compareUp()Source

Returns

  1. any...
compareDown()Source

Returns

  1. any...
attack([side])Source

Attack the entity in front of the turtle.

Parameters

  1. side? string The specific tool to use.

Returns

  1. boolean Whether an entity was attacked.
  2. string | nil The reason nothing was attacked.
attackUp([side])Source

Attack the entity above the turtle.

Parameters

  1. side? string The specific tool to use.

Returns

  1. boolean Whether an entity was attacked.
  2. string | nil The reason nothing was attacked.
attackDown([side])Source

Attack the entity below the turtle.

Parameters

  1. side? string The specific tool to use.

Returns

  1. boolean Whether an entity was attacked.
  2. string | nil The reason nothing was attacked.
suck([count])Source

Suck an item from the inventory in front of the turtle, or from an item floating in the world.

This will pull items into the first acceptable slot, starting at the currently selected one.

Parameters

  1. count? number The number of items to suck. If not given, up to a stack of items will be picked up.

Returns

  1. boolean Whether items were picked up.
  2. string | nil The reason the no items were picked up.

Throws

  • If given an invalid number of items.

suckUp([count])Source

Suck an item from the inventory above the turtle, or from an item floating in the world.

Parameters

  1. count? number The number of items to suck. If not given, up to a stack of items will be picked up.

Returns

  1. boolean Whether items were picked up.
  2. string | nil The reason the no items were picked up.

Throws

  • If given an invalid number of items.

suckDown([count])Source

Suck an item from the inventory below the turtle, or from an item floating in the world.

Parameters

  1. count? number The number of items to suck. If not given, up to a stack of items will be picked up.

Returns

  1. boolean Whether items were picked up.
  2. string | nil The reason the no items were picked up.

Throws

  • If given an invalid number of items.

getFuelLevel()Source

Returns

  1. any
refuel([countA])Source

Parameters

  1. countA? number

Returns

  1. any...
compareTo(slot)Source

Parameters

  1. slot number

Returns

  1. any...
transferTo(slotArg[, countArg])Source

Parameters

  1. slotArg number
  2. countArg? number

Returns

  1. any...
getSelectedSlot()Source

Get the currently sleected slot.

Returns

  1. number The current slot.

See also

getFuelLimit()Source

Returns

  1. any
equipLeft()Source

Returns

  1. any...
equipRight()Source

Returns

  1. any...
inspect()Source

Returns

  1. any...
inspectUp()Source

Returns

  1. any...
inspectDown()Source

Returns

  1. any...
getItemDetail([slot[, detailed]])Source

Get detailed information about the items in the given slot.

Parameters

  1. slot? number The slot to get information about. Defaults to the selected slot.
  2. detailed? boolean

    Whether to include "detailed" information. When true the method will contain much

                 more information about the item at the cost of taking longer to run.

Returns

  1. nil | table Information about the given slot, or nil if it is empty.

Throws

  • If the slot is out of range.

Usage

  • Print the current slot, assuming it contains 13 dirt.

     print(textutils.serialize(turtle.getItemDetail()))
     -- => {
     --  name = "minecraft:dirt",
     --  count = 13,
     -- }
     
craft(limit)Source

Parameters

  1. limit
nativeSource

The builtin turtle API, without any generated helper functions.

Generally you should not need to use this table - it only exists for backwards compatibility reasons.