commands.execAsync

From ComputerCraft Wiki
Revision as of 23:30, 16 February 2015 by Bomb Bloke (Talk | contribs) (More info.)

Jump to: navigation, search


Grid Redstone.png  Function commands.execAsync
Available only to Command Computers, executes the specified command, but doesn't yield. A "task_complete" event will be queued after the command is executed. You can use the taskID returned by this function to identify the "task_complete" event, should you wish to pull it. Compare commands.exec, which automatically yields until this event is thrown, then catches it and returns the results.

As this function allows huge amounts of commands to be requested in a very short time, no more than 1000 orders will be processed per server tick (the rest being queued until the next tick, and so on).

Accepts multiple parameters, in much the same manner as print, so long as they can all be serialised into one string. For example, commands.execAsync("setblock 0 70 0 minecraft:stone 0") is treated the same as commands.execAsync("setblock", 0, 70, 0, "minecraft:stone", 0). If one of the parameters is a table, it will be automatically textutils.serializeJSON()'d (handy for dynamically generating NBT representations).
Syntax commands.execAsync(string command)
Returns number taskID
Part of ComputerCraft
API commands

Examples

Grid paper.png  Example
Says 'Hello' to the player, closest to the Command Computer.
Code
commands.execAsync( "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 taskID = commands.execAsync( "testfor @a[r=" .. radius .. "]")

local arePlayersAround
repeat
  local event, id, success, executed, error = os.pullEvent( "task_complete" )
  
  arePlayersAround = success and executed
until id == taskID

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