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
| Decision | Tutorial value | What 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.spawningprevents 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.
| Result | Meaning | First response |
|---|---|---|
OK | The process was scheduled. | Watch spawn.spawning on later ticks. |
ERR_NAME_EXISTS | A Creep already uses that name. | Check Game.creeps[CREEP_NAME] and the requested name. |
ERR_BUSY | The Spawn is already creating another Creep. | Wait until the current process finishes. |
ERR_NOT_ENOUGH_ENERGY | The Spawn and usable Extensions do not currently contain enough Energy. | Wait for Energy delivery; the tutorial body needs 200 Energy. |
ERR_INVALID_ARGS | The 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:
- The real call returns
OK. spawn.spawningdescribes the active process.- The remaining time decreases across later ticks.
- After completion,
Game.creeps['Worker1']exists. - The finished Creep contains
WORK,CARRY, andMOVE.
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;
dryRunreturnsOKbefore the real request;- the real request returns
OKonce; spawn.spawningbecomes active;Game.creeps['Worker1']appears after completion;- you can explain why
OKmeans 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.