Command Block (API)

From ComputerCraft Wiki
Jump to: navigation, search
This API requires the use of a wrapped peripheral!
This API does not behave like a regular API, to use it you must first wrap the peripheral and call the methods on the wrapped object. For more information see this page.

The Command Block API allows you to run commands in a Command Block, using it as a peripheral. (The peripheral can only be used if allowed in the config, which disables it by default.)

API

Functions exposed by the Command Block, where "commandBlock" is a wrapped Command Block:

Grid disk.png  Command Block (API)
Function Return values Description
commandBlock.getCommand() string command Returns a string containing the command currently inside the Command Block.
commandBlock.setCommand(string command) nil Sets the command in the Command Block to command. This does not run it.
commandBlock.runCommand() nil Runs the command inside the Command Block previously set by manually editing it or by using commandBlock.setCommand().


Usage

All Command Block functions are to be used after wrapping the block as a peripheral. Example:

local commandBlock = peripheral.wrap("left")

commandBlock.setCommand("time set 1000")
commandBlock.runCommand()

local currentCommand = commandBlock.getCommand()

Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox