# `Animations.play`

> Contract 2.0.0 · package sha256 `a857eca95b35921109faf997094bb4192f12527d9d0fcd4be7e97f06425bad6e` · generated from `configurator-runtime.d.ts` by `services/onsite-scripter/scripts/build-contract-docs.mjs`; edit the source, not this file.

Method of [`Animations`](Animations.md) · stable · since 2.0.0 · called as `session.animations.play`

```ts
play(target: string | Part, clip: string, options?: C & PlayOptions): Promise<Report>;
```

Plays a clip (look-only; a newer play of the same clip on that part takes it over). Outcome: 'committed' when it ends or holds its
last frame; with `loop: true`, once it has started. Through a `tx`: 'deferred', and it starts
when the commit is shown. Fires 'animation:started' when the clip was neither playing nor
paused (a takeover or a resume fires nothing), and 'animation:finished' when it ends.
A play on a clip that is playing or paused continues from its current time in the asked
direction, and the play it takes over resolves 'committed': a toggle mid-way turns round
instead of jumping (Web Animations `Animation.reverse()`). Any other play starts at the clip's
start, or at its end with `reverse`; [`stop`](Animations.stop.md) it first to restart a playing clip. A [`stop`](Animations.stop.md), a
[`reset`](Animations.reset.md), an exclusive play, a new asset version or the node's removal that ends a pending play
resolves it 'committed' then (through a `tx`, when that commit is shown; spec 6.3).
Errors: rejects HoloInputError on invalid input (`toggle` with `reverse: true`); AbortError when `signal` aborts first. A clip
the target doesn't hold, a target whose GLB isn't loaded yet, or an unknown `nodeId` is not
invalid input: it resolves `matched: 0`, changes nothing and records 'target-unmatched' with
`didYouMean` from `list(target)` (1.x returned false and warned with the clip names). So
await the scene write that loads the node before playing its clips.

## Options

Through [`Session`](Session.md):

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `actor` | `Actor` | the `expectGroup`'s actor when one is given, else 'app' | Who made the write. |
| `dryRun` | `boolean` | false | Runs and reports, then rolls back by design ('dry-run'). |
| `expectGroup` | `HistoryGroup` | undefined | A guard, checked at the call: this write belongs to the undo group you are running. |
| `expectRevision` | `number` | undefined (no check) | If-match on [`session.revision`](Session.revision.md). |
| `loop` | `boolean \| number` | false | true (open-ended) or a repeat count: a whole number from 1, the plays in all, after which the clip ends (anything else rejects HoloInputError('invalid-input')). |
| `origin` | `string` | null | Your tag, echoed unchanged in [`Report.origin`](ReportFields.origin.md) and `cause.origin`. |
| `reverse` | `boolean` | false | Play towards the start: from the end, or from where a playing or paused clip is (see `play`). |
| `signal` | `AbortSignal` | undefined | Cancels this call; the member's JSDoc says what an abort does. |
| `speed` | `number` | 1 | Playback rate; 1 is authored speed. |
| `supersede` | `boolean` | false (the write is queued behind the transaction and applies after it closes) | While a transaction is open: roll it back (it resolves 'superseded'); the writes queued behind it apply in call order, then this one, which supersedes an… |
| `toggle` | `boolean` | false | Play the opposite direction of the last play; on a playing or paused clip it turns round where the clip is (see `play`). |
| `undo` | `'rebase' \| (string & {})` | a recorded-state change gets one step labelled 'Change'; a look-only write gets none; the session's first model (cause 'load') gets none, whatever the label: it is the floor of history | An undo label makes this write one undo step. |

Through [`Tx`](Tx.md):

| Option | Type | Default | What it does |
| --- | --- | --- | --- |
| `loop` | `boolean \| number` | false | true (open-ended) or a repeat count: a whole number from 1, the plays in all, after which the clip ends (anything else rejects HoloInputError('invalid-input')). |
| `reverse` | `boolean` | false | Play towards the start: from the end, or from where a playing or paused clip is (see `play`). |
| `signal` | `AbortSignal` | undefined | Cancels this call; the member's JSDoc says what an abort does. |
| `speed` | `number` | 1 | Playback rate; 1 is authored speed. |
| `toggle` | `boolean` | false | Play the opposite direction of the last play; on a playing or paused clip it turns round where the clip is (see `play`). |

Refused here (typed `never`, so passing one fails to compile): `actor`, `checkpoint`, `dryRun`, `expectGroup`, `expectRevision`, `origin`, `supersede`, `undo`.

## Abort (`signal`)

This call is a write (`SignalOption.signal`, [the kinds of call](../read-this-first.md#conventions)).

> A write: before the commit point it rolls back and rejects AbortError; after it, no effect, except that a running camera move stops where the last frame drew it (`CameraMoveOptions`).
>
> Through a `tx` the commit point is the transaction's: aborting a write still loading rejects AbortError and stages nothing (catch it: unobserved, it rolls the transaction back, spec section 6.1, O6); aborting one already staged unstages it, its paths keeping the latest other write to them as after a failed savepoint (O7), and its Promise stays resolved 'staged'.

## Example

Imports: values (`has`, `validate`, the `Holo*Error` classes, the pure helpers) from `@holostep-configurators/runtime-client`, types from `@holostep-configurators/runtime-client/contract`, `/math` and `/testing` names from those entries; `boot` from the runtime module the root's `loadRuntimeAtFloor` resolves to. A type your page defines is your app's: declare it there, never import it from the package.

Compiled under the contract's strict settings (`examples/declaration/14-Animations.play.ts`):

```ts
import type { Session } from '@holostep-configurators/runtime-client/contract';
declare const session: Session;
declare const signal: AbortSignal;
declare const bedId: string;
declare const fanId: string;
// resolves when the clip ends: open, then closed
await session.animations.play(bedId, 'open', { toggle: true });
// open-ended: resolves once started
await session.animations.play(fanId, 'spin', { loop: true });
```

## Generic-API test (spec 3.1)

| Rule | Result |
| --- | --- |
| 1. Neutral name | pass: `play` names no product |
| 2. A precedent | pass: [glTF 2.0 animations](https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#animations) (row `G52`); [Unity Animation.Play](https://docs.unity3d.com/ScriptReference/Animation.Play.html) (row `K64`) |
| 3. Two apps, or labs | pass: 10 apps (ledger: app-0c773a4ee3, app-b362a81c85, app-f3598fad77, app-fb16dd1985, app-fc07850558, app-fd09090420; fleet cross-check: app-04c2774145, app-0c773a4ee3, app-4762caacdc, app-b362a81c85, app-bcb7ef21da, app-f9a32142f1, app-fb16dd1985, app-fd09090420) |
| 4. The cheaper fix first | decided per need in Appendix B: rows `G52`, `K64` at tier labs, stable (a member only where no rule, data, asset or app code serves the need) |
