# defineRoom() function

> The defineRoom() function checks a room definition and returns it, as a room module's default export.

The **`defineRoom()`** function checks a [room definition](/docs/room/room-definition) and returns it. A room module's default export is its result.

## Syntax

```ts
defineRoom(definition)
```

### Parameters

`definition`
: A [`RoomDefinition`](/docs/room/room-definition): the room's schema, tick rate, stepper, interest and other settings, and its hooks.

### Return value

The same definition, typed without its entity kinds, which only type its `writes` handlers.

### Exceptions

`RangeError`
: Thrown for a `tickRate` that isn't an integer from 1 to 120, a `sleep.after` that isn't a positive number of milliseconds, or a `privateRetention` that isn't a positive number of milliseconds or `"forever"`.

`Error`
: Thrown for `onTick`, a `stepper`, a `history` or a bot behaviour with a `tick` hook in a room without a `tickRate`; for a `history` of a kind that isn't one of the schema's entity kinds; and for a `writes` key that isn't the private kind or an entity kind with writable fields.

The types reject most of these too.

## Examples

### A turn-based room without ticks

```ts
// checkers.ts
import { defineRoom, defineSchema, entity } from "@irtio/room";

const Game = entity("game", { turn: "string", moves: "u16" });

export default defineRoom({
  schema: defineSchema({ state: Game }),
  onJoin(room, connection) {
    if (room.state.turn === "") room.state.turn = connection.player;
  },
  onMessage(room, connection) {
    if (room.state.turn === connection.player) room.state.moves++;
  },
});
```

## See also

- [`RoomDefinition`](/docs/room/room-definition)
- [`defineSchema()`](/docs/room/defineschema)
- [With or without ticks](/docs/room/sdk#with-or-without-ticks)
