Difference between revisions of "Command Block (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Fixed grammar (hopefully) and improved example)
m (Wiki table.)
Line 1: Line 1:
 
{{PeripheralAPI}}
 
{{PeripheralAPI}}
  
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 to false by default)
+
(The peripheral can only be used if allowed in the [[ComputerCraft.cfg|config]], which disables it by default.)
  
Functions exposed by the Command Block, where commandBlock is a wrapped Command Block:
+
==API==
 +
Functions exposed by the Command Block, where "commandBlock" is a [[peripheral.wrap|wrapped]] Command Block:
  
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
+
{| class="wikitable"
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
+
! width="100px" | Returns
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
+
! width="200px" | Method name
Command Block (API)
+
! Description
</td></tr>
+
|-
 
+
|{{type|string}} command
<tr><td style="width: 350px; background: #E0E0E0; padding: .4em; font-weight:bold;">Method Name</td><td style="background: #E0E0E0; padding: .4em; font-weight:bold;">Description</td></tr>
+
|[[commandBlock.getCommand]]()
 
+
|Returns a string containing the command currently inside the Command Block.
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[commandBlock.getCommand]]()</td>
+
|-
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a string containing the command currently inside the Command Block.</td></tr>
+
|
 
+
|[[commandBlock.setCommand]]({{type|string}} command)
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[commandBlock.setCommand]]({{type|string}} command)</td>
+
|Sets the command in the Command Block to ''command''. '''This does not run it.'''
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sets the command in the Command Block to ''command''. '''This does not run it.'''</td></tr>
+
|-
 
+
|
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[commandBlock.runCommand]]()</td>
+
|[[commandBlock.runCommand]]()
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Runs the command inside the Command Block previously set by manually editing it or by using [[commandBlock.setCommand]]()</td></tr>
+
|Runs the command inside the Command Block previously set by manually editing it or by using [[commandBlock.setCommand]]().
</table>
+
|}
  
 
==Usage==
 
==Usage==

Revision as of 01:38, 1 April 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 disables it by default.)

API

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

Returns Method name Description
string command 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()