Task complete (event)
From ComputerCraft Wiki
Revision as of 19:17, 16 February 2015 by MKlegoman357 (Talk | contribs) (Created page with "{{Event |name=task_complete |desc=Fired when an asynchronous task completes. Used by every commands API method which yields, including [[commands.execAsync]...")
Event task_complete | |
Fired when an asynchronous task completes. Used by every commands API method which yields, including commands.execAsync(), but excluding commands.getBlockPosition(). Also used internally by every command block's method. | |
Returned Object 1 | number taskID - the ID number of the task |
Returned Object 2 | boolean success - true if the task completed without error, false otherwise |
Returned Object 3 | [string error] - if success is false then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5, 6, etc.. |
Returned Object 4 | any param1, param2, ... - parameters, returned by the task |
Example | |
Waits for any task to complete and prints it's ID, if it succeeded and if not succeeded the error message. | |
Code |
local event, taskID, success, error = os.pullEvent( "task_complete" ) print( "Task ID: ", taskID ) print( "Task succeeded: ", success ) if not success then print( "Error: ", error ) end |
Contents
commands.exec()/commands.execAsync()
Event task_complete | |
Fired when commands.exec()/commands.execAsync() is executed. This is used internally by commands.exec() and it is not needed to be used by the user. | |
Returned Object 1 | number taskID - the ID number of the task |
Returned Object 2 | boolean success - true if the task completed without error, false otherwise |
Returned Object 3 | [string error] - if success is false then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5, 6, etc.. |
Returned Object 4 | boolean commandResult - true if the command was executed successfully and returned positive value (a /testfor found a player), false if the command was not executed (invalid command or wrong arguments passed to the command) or it returned negative value (a /testfor didn't find a player) |
Returned Object 5 | [string error] - if commandResult is false then this is the error message saying why the command failed |
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 local errorMessage repeat local event, id, success, executed, error = os.pullEvent( "task_complete" ) arePlayersAround = success and executed if id == taskID then if not success then errorMessage = executed elseif not executed then errorMessage = error end end until id == taskID if errorMessage then print( "An error has occurred: ", errorMessage ) elseif arePlayersAround then print( "There is one or more players around me." ) else print( "There are no players around me." ) end |
commands.list()
Event task_complete | |
Fired when commands.list() completes. This is used internally by the function itself and it is not needed to be used by the user. | |
Returned Object 1 | number taskID - the ID number of the task |
Returned Object 2 | boolean success - true if the task completed without error, false otherwise |
Returned Object 3 | [string error] - if success is false then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5, 6, etc.. |
Returned Object 4 | table commands - a numerically indexed table filled with strings representing acceptable commands for commands.exec() / commands.execAsync() |
commands.getBlockInfo()
Event task_complete | |
Fired when commands.getBlockInfo() completes. This is used internally by the function itself and it is not needed to be used by the user. | |
Returned Object 1 | number taskID - the ID number of the task |
Returned Object 2 | boolean success - true if the task completed without error, false otherwise |
Returned Object 3 | [string error] - if success is false then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5, 6, etc.. |
Returned Object 4 | table blockInfo - a table containing information on the block at the specified world co-ordinate |
commandBlock.getCommand()
Event task_complete | |
Fired when commandBlock.getCommand() completes. This is used internally by the function itself and it is not needed to be used by the user. | |
Returned Object 1 | number taskID - the ID number of the task |
Returned Object 2 | boolean success - true if the task completed without error, false otherwise |
Returned Object 3 | [string error] - if success is false then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5, 6, etc.. |
Returned Object 4 | string command - the command in the command block |
commandBlock.setCommand()
Event task_complete | |
Fired when commandBlock.setCommand() completes. This is used internally by the function itself and it is not needed to be used by the user. | |
Returned Object 1 | number taskID - the ID number of the task |
Returned Object 2 | boolean success - true if the task completed without error, false otherwise |
Returned Object 3 | [string error] - if success is false then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5, 6, etc.. |
commandBlock.runCommand()
Event task_complete | |
Fired when commandBlock.runCommand() completes. This is used internally by the function itself and it is not needed to be used by the user. | |
Returned Object 1 | number taskID - the ID number of the task |
Returned Object 2 | boolean success - true if the task completed without error, false otherwise |
Returned Object 3 | [string error] - if success is false then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5, 6, etc.. |
Returned Object 4 | boolean commandResult - true if the command was executed successfully and returned positive value (a /testfor found a player), false if the command was not executed (invalid command or wrong arguments passed to the command) or it returned negative value (a /testfor didn't find a player) |
Returned Object 5 | [string error] - if commandResult is false then this is the error message saying why the command failed |