commands.exec

From ComputerCraft Wiki
Revision as of 17:05, 16 February 2015 by MKlegoman357 (Talk | contribs) (Created page with "{{lowercase}} {{Function |name=commands.exec |args={{type|string}} command |returns={{type|boolean}} success [<nowiki/>, {{type|string}} error] |api=commands |addon=ComputerCr...")

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


Grid Redstone.png  Function commands.exec
Available only to Command Computers, executes the command command, yields until the result is determined, then returns it. If command executes successfully then it returns true, otherwise returns false + an error message.
Syntax commands.exec(string command)
Returns boolean success [, string error]
Part of ComputerCraft
API commands

Examples

Grid paper.png  Example
Says 'Hello' to the player, closest to the Command Computer.
Code
commands.exec( "say @p Hello" )



Grid paper.png  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


Grid disk.png Commands API Functions
commands.exec - commands.execAsync - commands.list - commands.getBlockPosition - commands.getBlockInfo - commands.getBlockInfos