Goodluck / API Reference

Task

The Task component is used to schedule tasks to be executed at a later time.

A task can either complete when a predicate is met, or after a certain amount of time has passed, or as soon as possible. The Children component can be additionally used to create dependencies between tasks, with child tasks blocking the parent.

instantiate(game, [
    // 3. Then run do_something().
    task_then(() => do_something()),
    children([
        // 2. Then wait for 10 seconds.
        task_delay(10),
        children([
            // 1. First wait for is_something_true() to return true.
            task_when(() => is_something_true()),
        ]),
    ]),
]);

When a task completes, its entity is destroyed. For this reason, when adding tasks to entities which represent game objects, don't mix them with other components; add them as children instead.

instantiate(game, [
    transform(...),
    render(...),
    control_player(...),
    children([
        // This child entity is safe to destroy after the task completes.
        task_then(() => do_something()),
        children([
            task_delay(10),
        ]),
    ]),
]);