Commands (API)

From ComputerCraft Wiki
Revision as of 12:34, 16 February 2015 by 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...")

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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 / table par1, ...) boolean success Executes the specified command, yields until the result is determined, then returns it.
commands.execAsync(string / table par1, ...) nil Executes the specified command, but neither yields nor returns the result.
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 system 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).

Note: Most commands returned by commands.list() are also available as functions, such that commands.exec(par1, par2) could also be written as commands.par1(par2) - eg, commands.exec("msg", "@p Hello world!") becomes commands.msg("@p Hello world!").