Basic move script doesn't work
-
I am just new to this game and I have created a very simple move script. I know it isn't efficient at all but my harvester just doesn't move. What do I have to do to solve this problem? It doesn't give any errors
I have created this creep with the following commandline:
Game.spawns['Spawn1'].spawnCreep([MOVE, WORK, CARRY], 'Harvester')
Main:
var roleHarvester = require('role.harvester'); var roleDefender = require('role.defender'); var roleBuilder = require('role.builder') module.exports.loop = function () { var amountOfCreeps = 0; for(var name in Game.creeps) { if (name.name == 'Builder') { var creep = Game.creeps[name]; roleBuilder.run(creep); } else if (name.name == 'Harvester') { var creep = Game.creeps[name]; roleHarvester.run(creep); } else if (name.name == 'Defender') { var creep = Game.creeps[name]; roleDefender.run(creep); } amountOfCreeps++; } }
role.builder:
var roleBuilder = { /** @param {Creep} creep **/ run: function(creep) { if (creep.carry.energy === 0) { if (creep.withdraw(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(Game.spawns['Spawn1']); } } else { var sources = creep.room.find(FIND_STRUCTURES); if (creep.build(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0]); } } } }; module.exports = roleBuilder;
role.defender (not yet edited to my liking):
var roleDefender = { /** @param {Creep} creep **/ run: function(creep) { if(creep.carry.energy < creep.carryCapacity) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0]); } } else { if(creep.transfer(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(Game.spawns['Spawn1']); } } } }; module.exports = roleDefender;
role.harvester:
var roleHarvester = { /** @param {Creep} creep **/ run: function(creep) { if(creep.carry.energy < creep.carryCapacity) { var sources = creep.room.find(FIND_SOURCES); if(creep.harvest(sources[0]) == ERR_NOT_IN_RANGE) { creep.moveTo(sources[0]); } } else { if(creep.transfer(Game.spawns['Spawn1'], RESOURCE_ENERGY) == ERR_NOT_IN_RANGE) { creep.moveTo(Game.spawns['Spawn1']); } } } };
-
Hi! You should just test, which of your code is executed (e.g. via console.log)...
First failure is here:
for(var name in Game.creeps) { if (name.name == 'Builder') {
name.name doesn't sound legit