# Creating an empty gamemode

A gamemode is a feature provided by the `core` modules, as part of the normal level load and initialization process. It means you can attach a game mode to specific levels and then whenever you load that [level](https://docs.torque3d.org/for-designers/scenes-and-levels), the gamemode will be activated.

Before you dive into this part of the tutorial, make sure to create an empty level in the CoinCollection module. Open the [World Editor](https://docs.torque3d.org/getting-started/getting-familiar/launching-the-game/launching-the-editors), click on `File` in the top-left toolbar and choose `New Level` then click `Save Level` and make sure to place it in our CoinCollection module like this:

![](https://1474639700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXe4ekLqNACmy9Udfvs4k%2Fuploads%2FCnc483fd8G1bgHhJNdgL%2Fimage.png?alt=media\&token=5b1077a1-f0f5-44ce-909c-7e97fd85301a)

### The game mode

We need to be able to initialise the game mode, create a new file in `data/CoinCollection/server/gamemode.tscript` with the following contents:

```csharp
function CoinCollectionGameMode::onCreateGame() {
    // Note: The Game object will be cleaned up by MissionCleanup.  
    // Therefore its lifetime is limited to that of the mission.
    new ScriptObject(CoinCollectionGameMode) {
    };

    return CoinCollectionGameMode;
}
```

This is a *static* method and it is called from the `core` scripts.

Add the following piece of code to the end of `gamemode.tscript`:

```csharp
function CoinCollectionGameMode::onMissionStart(%this) {
    echo("CoinCollection mission has been loaded");
}
```

This does what it says on the tin, it's a method on the `CoinCollectionGameMode` object that is triggered when the mission starts, after the mission finish loading.

Since we added a new script file, we'll need to execute it, in the file `data/CoinCollection/CoinCollection.tscript` , change the function `initServer` to the following:&#x20;

```csharp
function CoinCollection::initServer(%this) {
    %this.queueExec("./server/gamemode.tscript");
}
```

Now, we need to associate our gamemode with the level. First select the scene object in the scene tree:\
![](https://1474639700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXe4ekLqNACmy9Udfvs4k%2Fuploads%2Fc62WZHjT58QQ1YuDCuVE%2Fimage.png?alt=media\&token=53172226-cc62-45f6-90bd-a10af0f618b5)

Then set the gameModeName of the scene object to `CoinCollectionGameMode`:

![](https://1474639700-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FXe4ekLqNACmy9Udfvs4k%2Fuploads%2F6k5jq7WA1OP411y9I7BK%2Fimage.png?alt=media\&token=de150715-cad0-4ad8-a872-724ed12c147e)

Remember to save your level.

Finally, go back to the main menu, click `Single Player`, choose your level and run it. Then look in the Console (tilde on US-layouts, for me it's the ½ key), and see if the message "CoinCollection mission has been loaded" is printed.

If it is, then awesome! Your gamemode is working! However, it's a rather boring game, you can't really move around in the game or do anything really.
