Difference between revisions of "Commands (API)"
From ComputerCraft Wiki
Bomb Bloke (Talk | contribs) (Created page with "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 direct...") |
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)) |
||
Line 5: | Line 5: | ||
{{API table/row | {{API table/row | ||
− | |[[commands.exec]]({{type|string}} | + | |[[commands.exec]]({{type|string}} command) |
|{{type|boolean}} success | |{{type|boolean}} success | ||
|Executes the specified command, yields until the result is determined, then returns it.}} | |Executes the specified command, yields until the result is determined, then returns it.}} | ||
{{API table/row | {{API table/row | ||
− | |[[commands.execAsync]]({{type|string}} | + | |[[commands.execAsync]]({{type|string}} command) |
− | |{{type| | + | |{{type|number}} commandID |
− | |Executes the specified command, but | + | |Executes the specified command, but doesn't yield. Queues a [[task_complete_(event)|"task_complete"]] event after the command is executed. |
|odd}} | |odd}} | ||
Line 18: | Line 18: | ||
|[[commands.list]]() | |[[commands.list]]() | ||
|{{type|table}} commands | |{{type|table}} commands | ||
− | |Returns a numerically indexed table filled with strings representing acceptable commands for [[commands.exec | + | |Returns a numerically indexed table filled with strings representing acceptable commands for [[commands.exec]]() / [[commands.execAsync]]().}} |
{{API table/row | {{API table/row | ||
|[[commands.getBlockPosition]]() | |[[commands.getBlockPosition]]() | ||
|{{type|number}} x, {{type|number}} y, {{type|number}} z | |{{type|number}} x, {{type|number}} y, {{type|number}} z | ||
− | |Returns the MineCraft world co-ordinates of the | + | |Returns the MineCraft world co-ordinates of the computer running the command. |
|odd}} | |odd}} | ||
Line 33: | Line 33: | ||
}} | }} | ||
− | + | ==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 [[os.pullEvent|yield]] before executing any more commands. | ||
[[Category:APIs]] | [[Category:APIs]] |
Revision as of 14:39, 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
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.