Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Basics
A task is like a little function.
However, there are two important differences:
Importantly, this is a safe and low-overhead wait, which should be much more efficient than a busy-waiting
while <...>: wait 1 tick
.The trigger will sleep until the task reports as finished (or cancelled). Other triggers are not affected: Skript can process everything else while that trigger is sleeping.
Waiting
A task can be waited for.
The wait will automatically end if:
If a task does not mark itself 'complete' at the end, it will be waited for indefinitely.
This is by design: a task can be completed and/or cancelled from another trigger.
You can use this to set up safe delays of indeterminate time.
Auto-completion
A task can be set to auto-complete when it reaches the end of its trigger.
Please note: this completion will occur the first time the task is delayed, stopped or suspended, rather than necessarily at the end of the section. It is just a safety measure for non-delayed tasks.
Cancellation
Like events, tasks can be 'cancelled'. This will wake up any trigger currently awaiting the task. Triggers will never wait for a cancelled task.
Cancellation will also attempt to stop the actual running of the task at a safe point.
Safe cancellation points currently include: delays, loops.
Cancellation and completion are the same, except that cancellation attempts to stop the task itself.
You can check for cancellation and completion individually.
Related Issues: #6230, #5563