# What's the function to calculate creep cost?

• So, I'm new to screeps and am currently trying to figure out the function for the energy cost of the spawnCreep method for a given body, but it seems to depend on more than just body size. Does anyone know the how to calculate that? Because I can't find anything in the documentation.

• Hi,

things are difficult in the beginning Try start with these:

https://docs.screeps.com/api/#StructureSpawn.spawnCreep

https://docs.screeps.com/api/#Constants

BODYPART_COST: { "move": 50, "work": 100, "attack": 80, "carry": 50, "heal": 250, "ranged_attack": 150, "tough": 10, "claim": 600 }

PS: I don't think there is a function, you have to write one Or find different solutions.

• Alright, that answers my question, thanks a bunch.

• In case anyone is looking for an answer, here's one way to do it:

``````function bodyCost(body)
{
let sum = 0;
for (let i in body)
sum += BODYPART_COST[body[i]];
return sum;
}
``````

Then use it like so

``````console.log(bodyCost([WORK, CARRY, MOVE]));
``````

• ``````// oneliner with lodash
const bodyCost = _.sum([WORK,MOVE,CARRY], b => BODYPART_COST[b]);`````` 