# GDScript: Scheduler

Source: https://tweens.gd/gdscript/api/scheduler/

A `TweensGdScheduler` advances playback only when you call `update()`, for deterministic tests or objects outside the scene tree. The automatic runner is built on one.

```gdscript
var scheduler := TweensGdScheduler.new()
var move := scheduler.add(sprite, Tweens.position_2d([100, 0], 1.0))
scheduler.update(0.5) # move.progress is now 0.5.
scheduler.dispose()
```

## Members

| Member | Type | Purpose |
| --- | --- | --- |
| [`add(target, definition, owner, options)`](https://tweens.gd/gdscript/api/scheduler/#add-target-definition-owner-options) | `TweensGdHandle` | Start one definition; a node target owns itself, other targets need no owner |
| [`add_all(target, definitions, owner, options)`](https://tweens.gd/gdscript/api/scheduler/#add-all-target-definitions-owner-options) | `TweensGdGroup` | Start an array of definitions as one [group](https://tweens.gd/gdscript/api/groups/) |
| [`add_chain(target, definitions, owner, options)`](https://tweens.gd/gdscript/api/scheduler/#add-chain-target-definitions-owner-options) | `TweensGdChain` | Start an array as one [Chain](https://tweens.gd/gdscript/api/chains/) |
| [`update(delta, unscaled_delta, mode)`](https://tweens.gd/gdscript/api/scheduler/#update-delta-unscaled-delta-mode) | `void` | Advance every tween of `mode`, which defaults to `PROCESS`. Tweens with unscaled time advance by `unscaled_delta`, which defaults to `delta` |
| [`active_count`](https://tweens.gd/gdscript/api/scheduler/#active-count) | `int` | Unfinished tweens; a Chain counts once |
| [`cancel_all()`](https://tweens.gd/gdscript/api/scheduler/#cancel-all) | `void` | Cancel every tween in this scheduler |
| [`cancel_owner(owner, include_children)`](https://tweens.gd/gdscript/api/scheduler/#cancel-owner-owner-include-children) | `void` | Cancel this scheduler’s tweens owned by a node, and optionally its descendants’ |
| [`last_error`](https://tweens.gd/gdscript/api/scheduler/#last-error) | `String` | The latest rejection or failure message |
| [`error_reported(message)`](https://tweens.gd/gdscript/api/scheduler/#error-reported-message) | signal | Emitted for each reported error |
| [`is_disposed`](https://tweens.gd/gdscript/api/scheduler/#is-disposed) | `bool` | True after `dispose()` |
| [`dispose()`](https://tweens.gd/gdscript/api/scheduler/#dispose) | `void` | Stop and settle the remaining playback |

`owner`, `options`, and `include_children` are optional.

## Plain objects

This example needs no scene or automatic runner. The scheduler advances a model halfway through a one-second motion:

meter\_example.gd

```gdscript
extends RefCounted

class Meter:
  var value := 0.0

static func sample_midpoint() -> float:
  var meter := Meter.new()
  var scheduler := TweensGdScheduler.new()
  var fill := Tweens.property(^"value", 100.0, 1.0)
  fill.from_value = 0.0
  scheduler.add(meter, fill)
  scheduler.update(0.5)
  scheduler.dispose()
  return meter.value # 50.0 with the default linear easing.
```

## Rules

-   A manual scheduler can animate objects without an owner. Node targets must still be inside the tree.
-   `update()` rejects invalid deltas, and recursive calls from inside a callback.
-   Tweens started during an update first advance on the next one, with no inherited time.
-   `Tweens.cancel_tweens()` reaches only the automatic runner; use `cancel_owner()` here.
-   Always dispose a manual scheduler, so remaining tweens end and run their callbacks.
