> For the complete documentation index, see [llms.txt](https://kinematicsoup.gitbook.io/reactor/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kinematicsoup.gitbook.io/reactor/architecture/update-loop.md).

# The Server Update Loop

## Summary

How to run code each frame on the server, and where your code sits relative to physics. For the full per-frame execution order, see [Server Execution Order](/reactor/examples/execution_order.md). This page is part of the [Reactor Technical Overview](/reactor/architecture.md).

## Running Code Each Frame

Server scripts do not override an `Update` method. Instead you register a handler on the room's ordered update event, keyed by an integer that sets when it runs:

```csharp
public override void Initialize()
{
    Room.OnUpdate[10] += MyUpdate;   // runs after physics
}

public override void Detached()
{
    Room.OnUpdate[10] -= MyUpdate;   // always unregister
}

private void MyUpdate() { /* per-frame logic */ }
```

Register in `Initialize` and unregister in `Detached`. Room, player, and entity scripts all use this same room-level event; there is no separate per-entity update method.

## Order and Physics

Handlers run in order of their integer key. The physics step, when the room uses it, runs at the boundary between negative and non-negative keys: **handlers with a negative key run before physics, and handlers with a zero or positive key run after**. Choose a negative key to act before physics, for example to apply forces, and a non-negative key to read the settled result.

Setting `Room.SkipFrameUpdates` to `true` during a handler stops handlers with a higher key from running this frame. It does not stop other handlers registered with the same key.

For the full order of a frame, including where input, RPCs, and syncs fall, see [Server Execution Order](/reactor/examples/execution_order.md).

## Time

Read time from `Room.Time`: the current `Frame`, total simulated `Time`, `RealDelta` (real seconds since the last frame), `FramesUntilSync` (frames until the next sync), and `TimeScale`, a multiplier you set to speed up or slow down simulated time. See [Changing Simulation Time](/reactor/examples/timescaling.md).

## Where to Go Next

* [Server Object Model](/reactor/architecture/server-object-model.md): the room, players, and entities your handlers act on.
* [The Runtime Server](/reactor/architecture/architecture-server.md): the loop in its wider context.
* [Server Execution Order](/reactor/examples/execution_order.md): the full per-frame order.
