Difference between revisions of "Command Block (API)"
From ComputerCraft Wiki
m (Fix typo (Where does peripheral "warping" come from, anyhow?)) |
MKlegoman357 (Talk | contribs) (Fixed return parameters) |
||
(8 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
− | + | {{PeripheralAPI}} | |
− | + | ||
− | Functions exposed by the Command Block, where commandBlock is | + | 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 [[ComputerCraft.cfg|config]], which disables it by default.) Under CC 1.7 or later, it may be easier to use a [[Command Computer]]. |
− | + | ||
− | + | ==API== | |
− | + | Functions exposed by the Command Block, where "commandBlock" is a [[peripheral.wrap|wrapped]] Command Block: | |
− | |[[commandBlock.getCommand]]( ) | + | {{API table|Command Block|image=Grid disk.png|2= |
+ | |||
+ | {{API table/row | ||
+ | |[[commandBlock.getCommand|''commandBlock''.getCommand]]() | ||
+ | |{{type|string}} command | ||
|Returns a string containing the command currently inside the Command Block. | |Returns a string containing the command currently inside the Command Block. | ||
− | | | + | |odd}} |
− | |[[commandBlock.setCommand]]( | + | |
− | |Sets the command in the Command Block. '''This does not run it.''' | + | {{API table/row |
− | + | |[[commandBlock.setCommand|''commandBlock''.setCommand]]({{type|string}} command) | |
− | |[[commandBlock.runCommand]]( ) | + | |{{type|nil}} |
− | |Runs the command inside the Command Block previously set by [[commandBlock.setCommand]]( ) | + | |Sets the command in the Command Block to ''command''. '''This does not run it.'''}} |
− | |} | + | |
+ | {{API table/row | ||
+ | |[[commandBlock.runCommand|''commandBlock''.runCommand]]() | ||
+ | |{{type|boolean}} success [<nowiki/>, {{type|string}} error] | ||
+ | |Runs the command inside the Command Block previously set by manually editing it or by using [[commandBlock.setCommand|''commandBlock''.setCommand]](). | ||
+ | |odd}} | ||
+ | }} | ||
− | == | + | ==Usage== |
− | All Command Block functions are to be used ''after'' wrapping the block | + | All Command Block functions are to be used ''after'' [[peripheral.wrap|wrapping]] the block as a peripheral. |
− | ''' | + | '''Example''': |
<span> | <span> | ||
− | commandBlock = [[peripheral.wrap]]("left") | + | local commandBlock = [[peripheral.wrap]]("left") |
− | commandBlock.setCommand("time set 1000") | + | |
− | commandBlock.runCommand() | + | [[commandBlock.setCommand]]("time set 1000") |
− | local currentCommand = commandBlock.getCommand() | + | [[commandBlock.runCommand]]() |
+ | |||
+ | local currentCommand = [[commandBlock.getCommand]]() | ||
</span> | </span> | ||
[[Category:Peripheral APIs]] | [[Category:Peripheral APIs]] |
Latest revision as of 19:25, 16 February 2015
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.) Under CC 1.7 or later, it may be easier to use a Command Computer.
API
Functions exposed by the Command Block, where "commandBlock" is a wrapped Command Block:
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() | boolean success [, string error] | 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()