---
url: /api/kiln/classes/StateValue.md
---
[Kiln API](../../index.md) / [kiln](../index.md) / StateValue

# Class: StateValue\<S>

A state's live value. Read it with `res.get(Screen)`, change it with `res.mut(Screen).set('playing')`.

## Type Parameters

| Type Parameter | Default type |
| ------ | ------ |
| `S` *extends* `string` | `string` |

## Constructors

### Constructor

```ts
new StateValue<S>(
   values, 
   initial, 
   inFixed, 
   frame, 
   tick
): StateValue<S>;
```

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `values` | readonly `S`\[] |
| `initial` | `S` |
| `inFixed` | () => `boolean` |
| `frame` | `number` |
| `tick` | `number` |

#### Returns

`StateValue`<`S`>

## Properties

### current

```ts
current: S;
```

The active value.

***

### previous

```ts
previous: S | null = null;
```

The value before the last transition, or null.

***

### next

```ts
next: S | null = null;
```

A transition requested with set(), applied at the start of the next frame.

***

### enteredFrame

```ts
enteredFrame: number;
```

Frame and fixed tick on which `current` was entered, for onEnter/onExit.

***

### enteredTick

```ts
enteredTick: number;
```

***

### values

```ts
readonly values: readonly S[];
```

## Methods

### set()

```ts
set(next): void;
```

Requests a transition. It applies at the start of the next frame; the last set() wins.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `next` | `S` |

#### Returns

`void`

***

### is()

```ts
is(value): boolean;
```

True while the state is `value`.

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `value` | `S` |

#### Returns

`boolean`

***

### justChanged()

```ts
justChanged(): boolean;
```

True during the first frame (or, in Fixed, the first fixed step) after a transition.

#### Returns

`boolean`

***

### toJSON()

```ts
toJSON(): object;
```

#### Returns

`object`

##### current

```ts
current: S;
```

##### previous

```ts
previous: S | null;
```

##### next

```ts
next: S | null;
```

##### enteredFrame

```ts
enteredFrame: number;
```

##### enteredTick

```ts
enteredTick: number;
```

***

### restore()

```ts
restore(json): void;
```

#### Parameters

| Parameter | Type |
| ------ | ------ |
| `json` | { `current`: `S`; `previous`: `S` | `null`; `next`: `S` | `null`; `enteredFrame`: `number`; `enteredTick`: `number`; } |
| `json.current` | `S` |
| `json.previous` | `S` | `null` |
| `json.next` | `S` | `null` |
| `json.enteredFrame` | `number` |
| `json.enteredTick` | `number` |

#### Returns

`void`
