Commands (API)
From ComputerCraft Wiki
Revision as of 14:39, 16 February 2015 by MKlegoman357 (Talk | contribs) (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))
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
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 commandID | 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.