Screeps: can creeps suck up energy from a spawn or an extension?

I recently started this game and I love the concept, however, while waiting to up my power level in the room controller, I was browsing around and found some code that suggested that creeps could transfer energy out of the spawn.

Lightbulb moment, I went to rewriting all my screep scripts except for the harvesters, simplifying them all down to nice clear levels ... but ... it didn't work.

I got the original idea from this ancient (5 years ago) thread: https://screeps.com/forum/topic/1550/repair-structure_-road/4

I've rewritten all my stuff back to using the energy sources, but I'm still curious, was it just something that changed in the screeps world? or is there a correct way to pull energy from a spawn or other item that is not a map source?

Upvotes: 2

Views: 1116

Answers (1)

KBill
KBill

Reputation: 85

If you want to withdraw Energy from a StructureSpawn, a StructureExtension or something else that have a Store it is possible (Container, Storage, ...)

// Your Creep
let creep = Game.creeps['Rico']
// Your Spawn
let spawn = Game.spawns['Scobar']

// And how Rico can withdraw some 'stuff' at the "Scobar" 
creep.withdraw(spawn.store)

See the documentation: Creeps withdraw function

Upvotes: 1

Related Questions