Difference between revisions of "Commands.execAsync"
From ComputerCraft Wiki
MKlegoman357 (Talk | contribs) (Created page with "{{lowercase}} {{Function |name=commands.execAsync |args={{type|string}} command |returns={{type|number}} taskID |api=commands |addon=ComputerCraft |desc=Available only to Co...") |
MKlegoman357 (Talk | contribs) (Corrected an example) |
||
Line 15: | Line 15: | ||
|desc=Checks if there are any players around the [[Command Computer]] in 2 block radius. | |desc=Checks if there are any players around the [[Command Computer]] in 2 block radius. | ||
|code=local radius = 2 | |code=local radius = 2 | ||
− | local taskID = '''commands. | + | local taskID = '''commands.execAsync( "testfor @a[r=" .. radius .. "]")''' |
local arePlayersAround | local arePlayersAround |
Revision as of 17:18, 16 February 2015
Function commands.execAsync | |
Available only to Command Computers, executes the specified command, but doesn't yield. Queues a "task_complete" event after the command is executed. You can use the taskID returned by this function to identify the "task_complete" event. | |
Syntax | commands.execAsync(string command) |
Returns | number taskID |
Part of | ComputerCraft |
API | commands |
Examples
Example | |
Says 'Hello' to the player, closest to the Command Computer. | |
Code |
commands.execAsync( "say @p Hello" ) |
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 |
Commands API Functions |
---|
commands.exec - commands.execAsync - commands.list - commands.getBlockPosition - commands.getBlockInfo - commands.getBlockInfos |