# A Steve is Born

## Initial setup

A very simple main.ts

{% code title="main.ts" %}

```typescript
//import { ErrorMapper } from "utils/ErrorMapper";
import { gameLoop } from "loop";

// When compiling TS to JS and bundling with rollup, the line numbers and file names in error messages change
// This utility uses source maps to get the line numbers and file names of the original, TS source code
//export const loop = ErrorMapper.wrapLoop(gameLoop);

export const loop = gameLoop;
```

{% endcode %}

The main loop code was moved to the 'loop.ts' file which holds the code responsible for handling each loop step. The main.ts then can optionally use the ErrorMapper or not.

{% code title="loop.ts" %}

```typescript
import { CreepManager } from "managers/CreepManager";
import { SpawnManager } from "managers/SpawnManager";
import { cleanMemory } from "utils/GameUtils";

export const gameLoop = () => {
  console.log(`Current game tick is ${Game.time}`);
  cleanMemory();

  SpawnManager.run();
  CreepManager.run();
};

```

{% endcode %}

### SpawnManager

The loop.ts module is responsible for calling the higher-level functions, like deleting creeps from memory that no longer exist and running the managers.

{% code title="SpawnMananger.ts" %}

```typescript
import { CreepRole } from "enums/CreepRole";

export class SpawnManager {

    public static run() {
        for (var name in Game.spawns) {
            var spawn = Game.spawns[name];
            SpawnManager.runSpawn(spawn);
        }
    }

    private static runSpawn(spawn: StructureSpawn) {
        var result = spawn.spawnCreep([WORK, MOVE, CARRY], "Steve", {
            dryRun: true
        });

        if (result === OK) {
            spawn.spawnCreep([WORK, MOVE, CARRY], "Steve", {
                dryRun: false,
                memory: {
                    role: CreepRole.steve,
                    room: "",
                    working: false
                }
            });
        }
    }

}

```

{% endcode %}

The SpawnManager is responsible for creating new creeps. This initial code only allows for one creep to exist at a time, called Steve. Steve is hard-coded to have a role of 'steve', but this will change in the future to be more dynamic.

![A Steve is Born](/files/-MZ8Bia13QbNWXfyNWnD)

The above GIF shows the code running in a training room.&#x20;


---

# 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://b-hub.gitbook.io/screeps/blog/adventures-of-steve/a-steve-is-born.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.
