> For the complete documentation index, see [llms.txt](https://docs.allout.game/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.allout.game/scripting/networking-fundamentals.md).

# Networking Fundamentals

All Out is multiplayer-first, but CSL is designed so you can write gameplay almost like it’s singleplayer.

The key idea is:

{% hint style="info" %}
All gameplay state is automatically synced from the server to clients. You do not need to write RPCs or “network spawn” things.
{% endhint %}

## Authority (who decides what?)

As a rule of thumb:

* **Server**: decides gameplay state (damage, rewards, spawns, win/loss, collisions-by-query, etc)
* **Client**: renders and plays cosmetics (UI, particles, screen shake, sound)

In practice, most of your code will run on both server and clients — you just guard *what work* runs where.

## Local vs server checks

Two checks you’ll use constantly:

* `is_local_or_server()`: for gameplay UI and input handling (runs on server + local client)
* `is_local()`: for purely cosmetic effects (runs only on the local client)

Example:

```go
Player :: class : Player_Base {
    ao_late_update :: method(dt: float) {
        // Use for gameplay UI and inputs (runs on server + local client)
        if is_local_or_server() {
            // draw_ability_button(this, Shoot_Ability, 0);
            // Handle inputs that affect game state
            // Movement is handled automatically
        }

        // Use for purely cosmetic effects (runs only on local client)
        if is_local() {
            // UI.text(..., "Waiting for host to start the game...");
            // Particle effects, cosmetic UI, etc.
        }
    }
}
```

{% hint style="warning" %}
If you run cosmetic-only work on the server, you’re wasting CPU (and potentially doing it multiple times). Keep cosmetics local.
{% endhint %}

## Client-specific state

Sometimes you need *local* state that should not affect gameplay and doesn’t need replication:

* UI open/close toggles
* Camera shake timers
* “last hovered item” in an inventory UI

Keep these as fields, but only read/write them behind `is_local()` checks.

```go
Player :: class : Player_Base {
    // Local-only UI state
    inventory_open: bool;

    ao_late_update :: method(dt: float) {
        if !is_local() return;

        // Toggle UI (example)
        // if UI.button(...) inventory_open = !inventory_open;
    }
}
```

## Multiplayer safety rules

* **Avoid global variables for player state.** If each player needs their own value, store it on `Player`.
* **Be careful with “singletons”.** If you truly need a global manager, make sure it doesn’t accidentally store per-player data.
* **Prefer deterministic server state.** The client should react to the server’s state, not invent it.

## Debugging networking issues

* Add `log_info(...)` on the server paths (not just local) so you can see authoritative decisions.
* If something “works locally” but not for other players, it’s usually:
  * code guarded by `is_local()` that should be server-authoritative, or
  * a global variable being overwritten by multiple players.

## Related docs

* [Adding Player Logic](/scripting/player-model.md)
* [Game/Frame Lifecycle](/scripting/game-frame-lifecycle.md)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.allout.game/scripting/networking-fundamentals.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
