Difference between revisions of "Task complete (event)"
From ComputerCraft Wiki
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]...") |
MKlegoman357 (Talk | contribs) m (Fixed/Improved) |
||
Line 25: | Line 25: | ||
|return1={{type|number}} taskID - the ID number of the task | |return1={{type|number}} taskID - the ID number of the task | ||
|return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | |return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | ||
− | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5 | + | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5 |
|return4={{type|boolean}} commandResult - <var>true</var> if the command was executed successfully and returned positive value (a /testfor found a player), <var>false</var> 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) | |return4={{type|boolean}} commandResult - <var>true</var> if the command was executed successfully and returned positive value (a /testfor found a player), <var>false</var> 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) | ||
|return5=[<nowiki/>{{type|string}} error] - if <var>commandResult</var> is <var>false</var> then this is the error message saying why the command failed | |return5=[<nowiki/>{{type|string}} error] - if <var>commandResult</var> is <var>false</var> then this is the error message saying why the command failed | ||
Line 36: | Line 36: | ||
local arePlayersAround | local arePlayersAround | ||
local errorMessage | local errorMessage | ||
− | + | while true do | |
local event, id, success, executed, error = [[os.pullEvent]]( [[task_complete_(event)|"task_complete"]] ) | local event, id, success, executed, error = [[os.pullEvent]]( [[task_complete_(event)|"task_complete"]] ) | ||
− | |||
− | |||
if id == taskID then | if id == taskID then | ||
+ | arePlayersAround = success and executed | ||
+ | |||
if not success then | if not success then | ||
errorMessage = executed | errorMessage = executed | ||
Line 47: | Line 47: | ||
errorMessage = error | errorMessage = error | ||
end | end | ||
+ | |||
+ | break | ||
end | end | ||
− | + | end | |
if errorMessage then | if errorMessage then | ||
Line 65: | Line 67: | ||
|return1={{type|number}} taskID - the ID number of the task | |return1={{type|number}} taskID - the ID number of the task | ||
|return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | |return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | ||
− | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place | + | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place |
|return4={{type|table}} commands - a numerically indexed table filled with strings representing acceptable commands for [[commands.exec]]() / [[commands.execAsync]]() | |return4={{type|table}} commands - a numerically indexed table filled with strings representing acceptable commands for [[commands.exec]]() / [[commands.execAsync]]() | ||
}} | }} | ||
Line 75: | Line 77: | ||
|return1={{type|number}} taskID - the ID number of the task | |return1={{type|number}} taskID - the ID number of the task | ||
|return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | |return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | ||
− | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place | + | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place |
|return4={{type|table}} blockInfo - a table containing information on the block at the specified world co-ordinate | |return4={{type|table}} blockInfo - a table containing information on the block at the specified world co-ordinate | ||
}} | }} | ||
Line 85: | Line 87: | ||
|return1={{type|number}} taskID - the ID number of the task | |return1={{type|number}} taskID - the ID number of the task | ||
|return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | |return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | ||
− | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place | + | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place |
|return4={{type|string}} command - the command in the command block | |return4={{type|string}} command - the command in the command block | ||
}} | }} | ||
Line 95: | Line 97: | ||
|return1={{type|number}} taskID - the ID number of the task | |return1={{type|number}} taskID - the ID number of the task | ||
|return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | |return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | ||
− | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed | + | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. |
}} | }} | ||
Line 104: | Line 106: | ||
|return1={{type|number}} taskID - the ID number of the task | |return1={{type|number}} taskID - the ID number of the task | ||
|return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | |return2={{type|boolean}} success - <var>true</var> if the task completed without error, <var>false</var> otherwise | ||
− | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5 | + | |return3=[<nowiki/>{{type|string}} error] - if <var>success</var> is <var>false</var> then this is the error message saying why the task failed. Otherwise returned object 4 takes it's place, fallowed by returned object 5 |
|return4={{type|boolean}} commandResult - <var>true</var> if the command was executed successfully and returned positive value (a /testfor found a player), <var>false</var> 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) | |return4={{type|boolean}} commandResult - <var>true</var> if the command was executed successfully and returned positive value (a /testfor found a player), <var>false</var> 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) | ||
|return5=[<nowiki/>{{type|string}} error] - if <var>commandResult</var> is <var>false</var> then this is the error message saying why the command failed | |return5=[<nowiki/>{{type|string}} error] - if <var>commandResult</var> is <var>false</var> then this is the error message saying why the command failed | ||
}} | }} |
Revision as of 19:23, 16 February 2015
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 |
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 while true do local event, id, success, executed, error = os.pullEvent( "task_complete" ) if id == taskID then arePlayersAround = success and executed if not success then errorMessage = executed elseif not executed then errorMessage = error end break end end 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 |
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 |
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 |
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. |
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 |
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 |