Difference between revisions of "Command Block (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Created the page)
 
Line 2: Line 2:
 
(The peripheral can only be used if allowed in the config, which is default to false)
 
(The peripheral can only be used if allowed in the config, which is default to false)
  
<table style="width: 100%; border: solid 1px black; margin: 2px; border-spacing: 0px;">
+
Functions exposed by the Command Block:
<tr><td colspan="2" style="font-weight: bold; font-size: large; padding-bottom: .3em; border-bottom: solid #C9C9C9 1px; background: #D3FFC2; line-height:28px;">
+
{| border="1" cellpadding="2" cellspacing="0"
[[File:Grid_disk.png|24px]]&nbsp;&nbsp;
+
!style="background:#EEE" width="200px"|Function
Command Block (API)
+
!style="background:#EEE" width="*"|Description
</td></tr>
+
|-
<tr style="background-color: #FFFFFF;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[command.getCommand]]()</td>
+
|getCommand( )
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Returns the command in the Command Block as a string.</td></tr>
+
|Returns a string containing the command currently inside the Command Block.
 
+
|-
<tr style="background-color: #E8E8E8;"><td style="border-top: solid #C9C9C9 1px; padding: .4em;">[[command.setCommand]]([[string]] command)</td>
+
|setCommand( [[string_(type)|string]] command )
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Sets the command currently in the Command Block.</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;">[[command.runCommand]]()</td>
+
|runCommand( )
<td style="border-top: solid #C9C9C9 1px; padding: .4em;">Runs the command currently in the Command Block.</td></tr>
+
|Runs the command inside the Command Block previously set by setCommand( )
</table>
+
|}
  
 
==Note==
 
==Note==
 
All Command Block functions are to be used ''after'' wrapping the block in a peripheral.
 
All Command Block functions are to be used ''after'' wrapping the block in a peripheral.
'''example''': command = peripheral.wrap("left")
+
'''example''':
 +
<span>
 +
command = peripheral.wrap("left")
 +
command.setCommand("time set 1000")
 +
command.runCommand()
 +
local currentCommand = command.getCommand()
 +
</span>
  
 
[[Category:Peripheral APIs]]
 
[[Category:Peripheral APIs]]

Revision as of 06:10, 30 March 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:

Function Description
getCommand( ) Returns a string containing the command currently inside the Command Block.
setCommand( string command ) Sets the command in the Command Block. This does not run it.
runCommand( ) Runs the command inside the Command Block previously set by setCommand( )

Note

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

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