# Counting coins

If we want the game to be a bit competitive, we need a scoring system. In a coin collection game, it makes sense that whoever picks up the most coins wins. Let's count how many coins we have picked up!

In `data/CoinCollection/server/coin.tscript` first add a global variable that counts the number of coins we've found at the top of the file:

```csharp
$CoinsFound = 0;
```

And then increment that number in the `onCollision` callback:

```csharp
function Coin::onCollision(%this, %obj, %col, %vec, %len) {
    %obj.delete();

    $CoinsFound++;
    if (Coins.getCount() <= 0) {
        commandToClient(%col.client, 'ShowVictory');
    }
}
```

And finally edit `data/CoinCollection/client/commands.tscript` to show the number of coins found in the message box using the `$CoinsFound` global:

```csharp
function clientCmdShowVictory()
{
    MessageBoxOK("You Win!",
            "Congratulation you found" SPC $CoinsFound SPC "coins!",
            "disconnect();" );
}
```


---

# Agent Instructions: 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:

```
GET https://docs.torque3d.org/getting-started/getting-familiar/your-first-game/counting-coins.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
