GETTING STARTED · BEGINNER LESSON 7 OF 12

How to Make a Screeps Spawn Create a New Creep

Use dryRun to validate a WORK-CARRY-MOVE body, submit one safe spawnCreep() request, read its return code, and verify the new Creep across later ticks.

Verification statusChinese source: Read in full · Official documentation: Checked · API and return codes: Checked

VERIFICATION

Evidence and test status

Chinese source
Read in full
Official documentation
Checked
API and return codes
Checked
JavaScript syntax
Checked
Offline branch review
Passed
Screeps Console
Pending — replace Spawn1 before running
Live spawn cycle
Pending — no live Worker1 completion is claimed
Last verified
July 27, 2026
Publication status
Ready

What you will complete in this lesson

This lesson has one goal: make one owned Spawn begin creating a new Creep named Worker1.

You will use the three-part learning body from the previous lesson:

[WORK, CARRY, MOVE]

The request costs 200 Energy. You will first validate it with dryRun, then submit the real request only when the validation result is OK.

Lesson boundary: this lesson creates one fixed-name Creep. Dynamic names, population targets, role Memory, replacement timing, and spawn queues belong in later guides.

A spawnCreep() request needs three decisions

DecisionTutorial valueWhat it controls
Which Spawn?Game.spawns['Spawn1']The owned structure that starts the process.
Which body?[WORK, CARRY, MOVE]The ordered list of body parts for the new Creep.
Which name?'Worker1'The unique key later used in Game.creeps.

Before copying the code, run Object.keys(Game.spawns) in the Console. Replace Spawn1 with the exact case-sensitive name returned by your game.

Review WORK, CARRY, and MOVE before changing the body array.

Validate the request with dryRun

State impact: validation only. A dryRun request checks whether spawning is currently possible without starting the process or spending Energy.

const SPAWN_NAME = 'Spawn1';
const CREEP_NAME = 'Worker1';
const BODY = [WORK, CARRY, MOVE];

const spawn = Game.spawns[SPAWN_NAME];

if (!spawn) {
  console.log(
    SPAWN_NAME +
    ' was not found. Check the name and capitalization.'
  );
} else {
  const bodyCost = BODY.reduce(function (total, part) {
    return total + BODYPART_COST[part];
  }, 0);

  const dryRunResult = spawn.spawnCreep(
    BODY,
    CREEP_NAME,
    { dryRun: true }
  );

  console.log(JSON.stringify({
    spawnName: spawn.name,
    spawnBusy: Boolean(spawn.spawning),
    nameAlreadyExists: Boolean(Game.creeps[CREEP_NAME]),
    roomEnergyAvailable: spawn.room.energyAvailable,
    bodyCost: bodyCost,
    dryRunResult: dryRunResult
  }, null, 2));
}

Do not continue to the real call until the Spawn name is correct and dryRunResult is OK.

Start one real spawning process

State impact: this code can consume room Energy and start a real spawn process. Replace Spawn1 before saving it.

const SPAWN_NAME = 'Spawn1';
const CREEP_NAME = 'Worker1';
const BODY = [WORK, CARRY, MOVE];

module.exports.loop = function () {
  const spawn = Game.spawns[SPAWN_NAME];

  if (!spawn) {
    console.log(
      SPAWN_NAME +
      ' was not found. Check the name and capitalization.'
    );
    return;
  }

  if (Game.creeps[CREEP_NAME] || spawn.spawning) {
    return;
  }

  const dryRunResult = spawn.spawnCreep(
    BODY,
    CREEP_NAME,
    { dryRun: true }
  );

  if (dryRunResult !== OK) {
    console.log(
      'Cannot start ' +
      CREEP_NAME +
      ': spawnCreep() returned ' +
      dryRunResult +
      '.'
    );
    return;
  }

  const spawnResult = spawn.spawnCreep(
    BODY,
    CREEP_NAME
  );

  console.log(
    spawnResult === OK
      ? CREEP_NAME + ' started spawning.'
      : 'Real spawn request returned ' + spawnResult + '.'
  );
};

The two guards matter because module.exports.loop runs again on later ticks:

  • Game.creeps[CREEP_NAME] prevents another request after the Creep exists.
  • spawn.spawning prevents another request while the Spawn is already working.

Read the return code before changing the body

OK means the spawn operation was scheduled successfully. It does not mean the completed Creep already exists.

ResultMeaningFirst response
OKThe process was scheduled.Watch spawn.spawning on later ticks.
ERR_NAME_EXISTSA Creep already uses that name.Check Game.creeps[CREEP_NAME] and the requested name.
ERR_BUSYThe Spawn is already creating another Creep.Wait until the current process finishes.
ERR_NOT_ENOUGH_ENERGYThe Spawn and usable Extensions do not currently contain enough Energy.Wait for Energy delivery; the tutorial body needs 200 Energy.
ERR_INVALID_ARGSThe body or name is invalid.Inspect every body constant and confirm that a name was provided.

Use the focused spawnCreep() return-code guide when a different result needs deeper diagnosis.

Watch the Spawn and the finished Creep on later ticks

The official constant CREEP_SPAWN_TIME is 3 ticks per body part. The three-part tutorial body therefore needs 9 ticks to finish under the current constant.

During the process, inspect:

const spawn = Game.spawns['Spawn1'];

console.log(JSON.stringify({
  tick: Game.time,
  spawning: spawn ? spawn.spawning : null,
  workerExists: Boolean(Game.creeps['Worker1'])
}, null, 2));

Expected sequence:

  1. The real call returns OK.
  2. spawn.spawning describes the active process.
  3. The remaining time decreases across later ticks.
  4. After completion, Game.creeps['Worker1'] exists.
  5. The finished Creep contains WORK, CARRY, and MOVE.

Fix the request, not an unrelated system

The Spawn object is undefined

The name is wrong or belongs to a different shard. Run Object.keys(Game.spawns) and copy the exact value.

The room never reaches 200 Energy

The body is valid, but the room economy is not refilling the Spawn or Extensions. Return to the Energy delivery lesson.

The Console prints the same failure every tick

This is temporary tutorial code. Use the return code to fix the request, then remove repeated diagnostic logging after the first successful spawn.

The real call returned OK, but Worker1 is still missing

Check spawn.spawning. A scheduled process still needs later ticks before the new Creep appears.

Completion check

You have completed this lesson when all of the following are true:

  • the code uses your real Spawn name;
  • dryRun returns OK before the real request;
  • the real request returns OK once;
  • spawn.spawning becomes active;
  • Game.creeps['Worker1'] appears after completion;
  • you can explain why OK means scheduled, not finished.

Give multiple Creeps simple responsibilities

You have created one fixed-name worker. The next lesson separates body abilities from player-defined jobs:

Understand Harvester, Upgrader, and Builder roles →

Return to the English beginner roadmap to review all twelve lessons in order.

Official sources

SOURCE AND SCOPE

Review the source, evidence, or next system

This English guide is rewritten for a focused search intent while preserving the technical scope and verification boundaries of its Chinese source. Live-room evidence is claimed only when the verification record says it exists.