Difference between revisions of "Command Block (API)"
From ComputerCraft Wiki
m (Added peripheral API message) |
MKlegoman357 (Talk | contribs) (Fixed grammar (hopefully) and improved example) |
||
Line 2: | Line 2: | ||
The Command Block API allows you to run commands in a Command Block, using it as a peripheral. | 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 is | + | (The peripheral can only be used if allowed in the config, which is to false by default) |
− | Functions exposed by the Command Block, where commandBlock is | + | Functions exposed by the Command Block, where commandBlock is a wrapped Command Block: |
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;"> | <table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;"> | ||
Line 24: | Line 24: | ||
</table> | </table> | ||
− | == | + | ==Usage== |
− | All Command Block functions are to be used ''after'' wrapping the block | + | All Command Block functions are to be used ''after'' 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]] |
Revision as of 21:55, 31 March 2014
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 is to false by default)
Functions exposed by the Command Block, where commandBlock is a wrapped Command Block:
Method Name | Description |
commandBlock.getCommand() | Returns a string containing the command currently inside the Command Block. |
commandBlock.setCommand(string command) | Sets the command in the Command Block to command. This does not run it. |
commandBlock.runCommand() | 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()