Difference between revisions of "Command Block (API)"

From ComputerCraft Wiki
Jump to: navigation, search
m (Fix typo (Where does peripheral "warping" come from, anyhow?))
(Updated table to v2)
Line 3: Line 3:
  
 
Functions exposed by the Command Block, where commandBlock is wrapped to a command block:
 
Functions exposed by the Command Block, where commandBlock is wrapped to a command block:
{| border="1" cellpadding="2" cellspacing="0"
+
 
!style="background:#EEE" width="*"|Function
+
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
!style="background:#EEE" width="*"|Description
+
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
|-
+
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
|[[commandBlock.getCommand]]( )
+
Command Block (API)
|Returns a string containing the command currently inside the Command Block.
+
</td></tr>
|-
+
 
|[[commandBlock.setCommand]]( [[string_(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>
|Sets the command in the Command Block. '''This does not run it.'''
+
 
|-
+
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[commandBlock.getCommand]]()</td>
|[[commandBlock.runCommand]]( )
+
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns a string containing the command currently inside the Command Block.</td></tr>
|Runs the command inside the Command Block previously set by [[commandBlock.setCommand]]( )
+
 
|}
+
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[commandBlock.setCommand]]({{type|string}} command)</td>
 +
<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>
 +
<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>
 +
</table>
  
 
==Note==
 
==Note==

Revision as of 13:51, 15 May 2013

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 default to false)

Functions exposed by the Command Block, where commandBlock is wrapped to a command block:

Grid disk.png   Command Block (API)

Method NameDescription
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()

Note

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

commandBlock = peripheral.wrap("left")
commandBlock.setCommand("time set 1000")
commandBlock.runCommand()
local currentCommand = commandBlock.getCommand()