To build structures with code in Screeps, you place a construction site with Room.createConstructionSite() or RoomPosition.createConstructionSite(), let a creep with a WORK part deliver energy to that site, and confirm the site has turned into a finished structure. The key condition is RCL: each room's controller level caps the total number and types of structures you can own, so a perfectly written build script still fails if your room hasn't leveled up to allow the building.

That's the whole loop in miniature. The rest of this guide is about doing it reliably: writing placement code that doesn't throw away energy on bad spots, deciding when your empire should build at all, queueing sites correctly so builders don't starve, and recovering when a site sits unfinished or gets torn down by an invader. It assumes you're comfortable with basic Screeps scripting—memory objects, creeps with roles, and the main loop—but not that you've ever automated construction before.

Screeps is a persistent JavaScript MMO where your code runs continuously on official servers, so every mistake in a build pipeline costs real CPU and real energy over many ticks. Getting the construction layer right pays off for the whole colony.

The Construction Pipeline From Decision To Finished Building

Before any specific code, you need the mental model. Construction in Screeps is a four-stage pipeline, and each stage has a different owner in your codebase.

Stage one is the decision. Some logic—a room planner, a spawn priority list, a defense routine—chooses that a structure should exist at a specific tile. This stage never touches the game API for building; it only decides what and where.

Stage two is site creation. You call the construction-site API and spend a small amount of energy from the room's storage or from creep-carried energy, depending on how you fund it. The result is a construction site object visible in room.find(FIND_CONSTRUCTION_SITES) and in room.myConstructionSites.

Stage three is building. Creeps with WORK parts call creep.build(site). Each unit of energy delivered adds progress. When site.progress reaches site.progressTotal, the site converts into a real structure, and the site object disappears.

Stage four is maintenance. Finished structures decay over time (most non-road structures lose hits slowly), and your code needs repair logic. Roads decay far faster than walls; ramparts don't decay at all but can be destroyed in combat. A build system that ignores decay creates a colony that dies of attrition.

The reason to separate these stages in your head—and ideally in separate modules—is that each one fails differently. A planner fault creates sites in bad locations. A site-creation fault throws errors and wastes ticks. A build fault leaves sites at 0% progress while creeps idle. A maintenance fault shows up days later as a collapsed wall or a road that vanished mid-haul. Debugging is vastly easier when you can point at one stage.

Prerequisites: Room Control Level, Energy, And Builder Creeps

You can't build anything in a room you don't own, and ownership alone isn't enough. The controller level (RCL) gates both how many structures you may own and which structure types unlock.

At RCL 1 you're limited to a tiny handful of structures—spawns, roads, and a few others—and the total count is small. Roads unlock early, which matters because early bases need hauling infrastructure almost immediately. Extensions unlock at RCL 2 along with more structure slots, containers at RCL 2 as well, towers at RCL 3, storage at RCL 4, and links at RCL 5. Walls and ramparts become available at RCL 2 and 3 respectively, but their hit-point caps climb with controller level, so early walls are thin by design. The exact per-level limits live in the game's structure constants and CONTROLLER_STRUCTURES table; check those values in-game rather than trusting a remembered list, because balance patches have moved them.

Energy is the second gate. Creating a construction site costs energy (the site itself has a small creation cost), and every point of progress requires energy delivered by builders. A site with a huge progressTotal—walls and ramparts scale steeply—can absorb thousands of energy, so the planner must weigh whether a thick wall is worth delaying extensions.

Builder creeps are the third gate. A builder needs WORK parts to contribute progress and CARRY parts to haul energy, plus MOVE to get around. Early builders are typically a hybrid role: they mine or withdraw energy, then build, then repair. Around RCL 3–4 you can split dedicated builders from haulers, but the split isn't free—each dedicated role adds spawn time and CPU for decision logic.

One practical prerequisite many new players miss: your spawn must have energy to make builders, and builders must have a path to the site. A site across an unreachable swamp with no roads will stall because builders spend all their ticks walking. Placement near existing roads and containers isn't cosmetic; it's throughput.

Writing The Core Build Call Correctly

The fundamental call is pos.createConstructionSite(x, y, structureType) or its room-level sibling room.createConstructionSite(x, y, structureType). The room-level version also accepts a structure type only when the position is inside that room; positions carry their own room reference, so the position method is the one to use when your coordinates might be at a room edge.

Three rules keep this call from becoming a source of silent bugs.

First, check the return code. The method returns OK on success or an error constant such as ERR_INVALID_TARGET, ERR_FULL (room has the maximum number of sites), ERR_RCL_NOT_ENOUGH, ERR_INVALID_ARGS, or ERR_NOT_OWNER. If you ignore the return value, your planner will happily try the same illegal placement every tick forever, burning CPU.

Second, guard against duplicates. A planner that runs each tick and creates a site whenever "no site exists for this structure" will recreate the site the moment it finishes, endlessly. Track intended structures in room memory or derive them from a deterministic plan, and skip creation if a matching site or finished structure already exists.

Third, only create sites when you mean to spend the energy. Site creation has a cost, and there's a cap on simultaneous sites per room (and a global site cap per player). A planner that queues twenty sites in a young room hits ERR_FULL and wastes the whole tick's planning logic.

A minimal, safe pattern looks like this in prose: iterate over your desired structures; for each one, compute the target position; query the room's construction sites and structures to see if one already occupies that tile or matches your intent; if not, call createConstructionSite and log a warning if the return code isn't OK. Wrap the whole planning function so it runs only when there's spare CPU and only when the room has enough energy to justify more building.

Placement Logic That Prevents Wasted Energy

Placement is where most build systems quietly bleed resources. A site built on a tile that blocks a critical chokepoint, or an extension built three tiles from the spawn when it could sit adjacent, costs hauling time for the rest of the room's life.

Start with hard constraints before aesthetic ones. Roads and structures can't overlap; a tile can hold one structure. The controller's own tile and the spawn's tile are occupied. Tiles occupied by sources, minerals, or extractors are off-limits. Creeps must be able to path around buildings—a wall of structures across a corridor turns your room into a maze and can trap creeps or block hauler routes entirely.

The most valuable placement habit is the stamp: a precomputed layout of relative offsets that you translate to an anchor position. Instead of deciding each extension tile by tile, define an extension cluster as a ring around the spawn, and have code place each member of the stamp if the tile is free. Stamps make placement deterministic, which means reproducible and debuggable. They also make memory cheap: you store an anchor and a stamp index, not twenty individual coordinates.

For roads, placement should follow actual traffic. A simple, effective heuristic: run your own pathfinding between key pairs (spawn to sources, spawn to controller, spawn to containers) and favor roads along those paths. Even better, record creep movement over a sample of ticks and place roads on the hottest tiles. A road on a tile nobody walks is pure decay cost.

For defenses, placement interacts with the terrain. Walls and ramparts belong on chokepoints, not scattered. Because ramparts are walkable by your creeps (and walls aren't), the typical pattern is a rampart wall with a wall behind it at key entries. Don't build walls early just because you can—low-RCL walls have pitiful hit-point caps, and an invader will chew through them while your energy is better spent on extensions.

One more placement trap: containers and storage near the action. Storing harvested energy in a container adjacent to the source cuts hauler travel. Placing storage near the spawn and extensions clusters cuts refill time. These two positions strangle or rescue an economy, and they're worth hand-picking before you generalize.

Prioritizing What To Build Next

When energy is scarce—which is most of the time in a young colony—the build queue is the real decision. A workable priority order for a typical room:

Energy infrastructure first: spawn, then extensions up to the current RCL cap, then containers at sources. Extensions raise the room's energy capacity, which raises how much a single spawn cycle can invest, which compounds. Container placement at sources lets miners drop energy instead of carrying it, which frees CARRY parts for other work.

Then roads on proven traffic, then towers for defense. Towers are the single best defensive structure per energy in the game, but they're only as good as their energy supply and placement—put them where they cover the room's vulnerable entries, and keep them filled.

Then storage, then links, then walls and ramparts in proportion to actual threat. Walls before storage is usually wrong: an unthreatened room with thick walls and no storage is a room with a stalled economy. A room that's getting raided with no walls is a room that will lose its storage anyway.

The general principle: build what increases income or reduces risk, in that order, and only spend on defense proportional to observed threat. If you're on a server with aggressive neighbors, shift defense up. If you're in a quiet corner, push economy.

You can encode this as a priority list of structure types with per-type caps, evaluated each planning tick, with a budget check: only create sites while the room's stored energy exceeds some fraction of its capacity. Keeping a reserve for spawning builders and refilling towers is part of the priority logic, not an afterthought.

Keeping Builders Busy And Preventing Stalled Sites

Site creation is worthless if builders don't build. Two failure modes dominate.

The idle builder problem. Builders assigned to a site that's unreachable, or that's already finished, will sit there or wander. The fix is a role script that, every tick, picks the nearest site with remaining progress that it can path to, and falls back to repair or upgrade work when none exists. If creep.build(site) returns ERR_NOT_IN_RANGE, move toward it; if it returns ERR_NOT_ENOUGH_ENERGY (in the sense that the creep has nothing to deliver), send it to withdraw; if it returns OK but progress isn't rising, something is wrong with the site's validity—check that it's still in the room's site list.

The starved-site problem. A site at 0% progress for hundreds of ticks is a site you probably shouldn't have created yet. Either the room can't afford it, or no builder is spawning. A useful diagnostic: track each site's progress in Memory on first sight, and if a site's progress hasn't changed in, say, 500 ticks, log a warning naming the site and the nearest builder's state. That warning is your early sign that the economy can't sustain the current build queue.

Builders also need to be resupplied efficiently. The classic mistake is a builder with two CARRY parts walking a long distance to a container, filling up, and walking back, spending most of its life in transit. Give builders enough CARRY to make a trip worthwhile, and place energy buffers near the build zone when you're building a big cluster. With links, late-game builders can pull from a link adjacent to the construction area.

Finally, cap how many sites you open at once. A room with ten open sites and three builders finishes nothing. Two or three concurrent sites per builder is a rough ceiling; when the site count exceeds builder throughput, the planner should pause.

Handling Errors, Limits, And Invader Damage

The API's failure modes are your early-warning system, and treating them as bugs-in-waiting saves whole colonies.

ERR_RCL_NOT_ENOUGH from createConstructionSite means your plan is ahead of your controller level. The right response isn't to retry; it's to stop planning that structure type until RCL rises, and to log it once so you know the plan and the level are out of sync.

ERR_FULL means the site cap is reached. Either you have too many queued sites, or the player-wide cap is hit across rooms. The planner should treat ERR_FULL as a stop signal for this tick, not retry in a loop.

ERR_INVALID_TARGET usually means the tile is occupied or out of bounds. A planner that computes positions from terrain now and decides years later can drift out of sync; recompute the target tile right before creating the site.

Finished structures can be destroyed—by invaders, by decay, or by your own mistakes. Your maintenance routine should scan room.find(FIND_STRUCTURES) and repair anything below a threshold, but with a budget: repairing a rampart to full health every tick can eat an entire room's income. Repair priority should follow threat and value—roads and containers first, walls only to a target percentage of their cap.

There's a deeper version of the invader problem: sites under construction are attackable, and creeps building at the room's edge are exposed. If you're getting raided, building at the periphery is a losing move. The safe pattern is to build inward-first—extensions and storage near the spawn—and only push defensive structures outward when you have towers and a reserve to defend them.

When to stop and call in help: if your room's energy is consistently below what's needed to spawn a builder and the cause isn't obvious from your logs, stop adding build sites and audit your spawn priority and hauling first. Building on a broken economy just spreads the damage. If you're on a private server, check the server logs for errors; if you're on an official server and a bug seems to affect only your account across rooms, consult the community forums and the game's issue tracker rather than patching blindly.

Worked Example: Scripting A Road Network From Traffic

Abstract advice becomes concrete with a worked sketch. Suppose you want roads on the tiles your creeps actually walk.

First, instrument movement. In your creep role scripts, every tick record the creep's current tile into a memory counter keyed by room and coordinate—something like Memory.traffic["W1N1:23,14"]++. This is cheap but grows; prune counters older than, say, a few thousand ticks, or use exponential decay so old traffic fades.

Second, run a planning function periodically (not every tick). Sort the traffic counters descending. For each hot tile above a threshold, check whether a road already exists there or a site is already queued; if not, and the room has energy to spare and the RCL allows roads, create the site.

Expected result: within a few hundred ticks, roads appear on the highest-traffic tiles first, in order of measured use.

How to check success: in the room visualizer or by scanning room.find(FIND_STRUCTURES, {filter: s => s.structureType === STRUCTURE_ROAD}), confirm road count rising over time and confirm that the busiest tiles are built before the cold ones. If sites sit at 0% while traffic is high, the problem is builder supply, not placement—go back to the builder role.

Note the arithmetic here: if a tile sees ten creep-passes per hundred ticks and each pass is a different creep, the road saves movement ticks roughly proportional to traffic, but a road decays. Below roughly a handful of passes per hundred ticks, the repair cost outweighs the movement savings, so the threshold matters more than the exact constant. The threshold is a judgment call you tune by watching repair costs.

Scaling The System Across Rooms

Once a single room's build loop is stable, the same pattern generalizes—with one important change: planning should be per-room but budgeting should be global.

Each room's planner computes its own desired structures and site queue, then applies for energy from the empire budget. In practice, memory-wise, that means room-level plan data plus a small global ledger of how much energy each room may spend on construction this tick. A young room gets priority for extensions; a mature room with capped extensions spends on walls and links; a room under attack vetoes economy building and spends on defense and repair.

Keep the planner idempotent. Running it twice in the same tick should produce the same result: no new sites, no new energy spent. This makes debugging far easier because you can re-run the planning sink mentally against memory state.

Cap total sites per room (the game's constants give the cap) and keep a global site budget to avoid starving your most important room with a lesser room's queue. And log every site creation and every planner decision once—one log line per new site, not per tick—so your history is readable later.

A final scaling caution: cross-room builders are tempting, but a builder that crosses a room boundary costs extra path computation and can get stranded. Until you have a dedicated hauling network, keep builders home. The savings from a cross-room build queue rarely outweigh the CPU and routing complexity.

FAQ

Can I place structures on top of each other or on occupied tiles? No. Each tile holds at most one structure or construction site, and special tiles (controller, sources, extractor, mineral) are reserved. Your planner must check occupation before creating a site.

Why did my construction site disappear without becoming a structure? Sites that are destroyed (by creeps, usually), or that decay when left at zero progress for long enough, are removed. If Memory still lists an intent, your planner may try to recreate it, so reconcile intents against the room's actual site and structure lists each planning pass.

Does a creep need to be adjacent to build? The creep must be within range of the site to use build; in practice that means standing on a tile within one step of the site's tile, and the creep moves there itself when you call creep.build and it's not yet in range. If ERR_NOT_IN_RANGE keeps returning, the site may be unreachable—check pathability.

How many construction sites can I have open at once? The game enforces both a per-room and a player-wide cap, and the cap interacts with RCL. Treat ERR_FULL as the authority: when you see it, stop creating sites this tick and rebalance your queue toward finishing existing ones.