I've written this code for my creep to pick up dropped energy but when it finds the dropped energy it just becomes paralyzed. Have I written anything wrong?
Code:
var roleHarvester = require('role.harvester');
var roleLabourer = {
run: function(creep){
var dropenergy = creep.pos.findClosestByPath(FIND_DROPPED_ENERGY)
if(dropenergy.length != 0){
if(creep.pickup(dropenergy[0]) == ERR_NOT_IN_RANGE){
creep.moveTo(dropenergy[0].pos)
}
if(creep.pickup(dropenergy[0]) == ERR_FULL){
var storages = Game.spawns.Spawn1.room.find(FIND_MY_STRUCTURES, { filter: { structureType: STRUCTURE_STORAGE }});
for (i = 0; i < storages.length; i++) {
if(storages[i].store[RESOURCE_ENERGY] < storages[i].storeCapacity){
if(creep.transfer(storages[i],RESOURCE_ENERGY,creep.carry.energy) == ERR_NOT_IN_RANGE){
creep.moveTo(storages[i])
}
}
}
}
}
else{
roleHarvester.run(creep)
}
}
}
module.exports = roleLabourer