Difference between revisions of "Commands (API)"

From ComputerCraft Wiki
Jump to: navigation, search
(Fixed parameter types and return values. Added a note about command limit. Changed formatting a bit. Lets stick with one API function link style in all of the wiki: commands.exec() (don't include parenthesis in the link))
m (renamed a return value)
Line 11: Line 11:
 
{{API table/row
 
{{API table/row
 
|[[commands.execAsync]]({{type|string}} command)
 
|[[commands.execAsync]]({{type|string}} command)
|{{type|number}} commandID
+
|{{type|number}} taskID
 
|Executes the specified command, but doesn't yield. Queues a [[task_complete_(event)|"task_complete"]] event after the command is executed.
 
|Executes the specified command, but doesn't yield. Queues a [[task_complete_(event)|"task_complete"]] event after the command is executed.
 
|odd}}
 
|odd}}

Revision as of 17:28, 16 February 2015

Only available to the fabled Command Computer (itself only available to ops in creative mode, running CC 1.7 or later), the commands API allows your system to directly execute MineCraft commands and gather data from the results.

API

Grid disk.png  commands (API)
Function Return values Description
commands.exec(string command) boolean success Executes the specified command, yields until the result is determined, then returns it.
commands.execAsync(string command) number taskID Executes the specified command, but doesn't yield. Queues a "task_complete" event after the command is executed.
commands.list() table commands Returns a numerically indexed table filled with strings representing acceptable commands for commands.exec() / commands.execAsync().
commands.getBlockPosition() number x, number y, number z Returns the MineCraft world co-ordinates of the computer running the command.
commands.getBlockInfo(number x, number y, number z) table block info Returns a table containing info about the block at the specified world location. Keys are "name" (a string) and "metadata" (a number).

Notes

  • Most commands returned by commands.list() are also available as functions, such that commands.exec(command) could also be written as commands.command(par1, par2, ...) - eg, commands.exec("msg @p Hello world!") becomes commands.msg("@p Hello world!").
  • There is a 1000 command limit per tick. After executing 1000 commands, you should yield before executing any more commands.