commands.exec
From ComputerCraft Wiki
Revision as of 08:26, 17 February 2015 by MKlegoman357 (Talk | contribs) (Removed misinformation. commands.exec/execAsync only allows to pass one string: the command. Only commands.<command>() where <command> is an actual MC command allows multiple parameters, including numbers and tables)
Function commands.exec | |
Available only to Command Computers, executes the specified MineCraft command, yields until the result is determined, then returns it. If command executes successfully then it returns true, otherwise returns false + an error message. Compare commands.execAsync, which ignores the result and returns immediately, without yielding.
| |
Syntax | commands.exec(string command) |
Returns | boolean success [, string error] |
Part of | ComputerCraft |
API | commands |
Examples
Example | |
Says 'Hello' to the player, closest to the Command Computer. | |
Code |
commands.exec( "say @p Hello" ) |
Example | |
Checks if there are any players around the Command Computer in 2 block radius. | |
Code |
local radius = 2 local arePlayersAround = commands.exec( "testfor @a[r=" .. radius .. "]") if arePlayersAround then print( "There is one or more players around me." ) else print( "There are no players around me." ) end |
Commands API Functions |
---|
commands.exec - commands.execAsync - commands.list - commands.getBlockPosition - commands.getBlockInfo - commands.getBlockInfos |