movement?
Posts made by EPICBRONY
-
creep is not defined?
ReferenceError: creep is not defined
at main:2:4
at n:5:28406
at Object.c.runCode:5:34007
that is the error, what is up?
and here is the script in main that I was using// memory roles if(creep.memory.role == 'harvester') { harvester(creep); } if(creep.memory.role == 'builder') { builder(creep); } if(creep.memory.role == 'guard') { guard(creep); } if (creep.memory.role == 'harvester'){ if(creep.carry.energy < creep.carryCapacity) { var sources = creep.room.find(FIND_SOURCES); creep.moveTo(sources[0]); creep.harvest(sources[0]); } else { creep.moveTo(Game.spawns.Spawn1); creep.transferEnergy(Game.spawns.Spawn1); } } if(creep.memory.role == 'builder') { if(creep.carry.energy === 0) { creep.moveTo(Game.spawns.Spawn1); Game.spawns.Spawn1.transferEnergy(creep); } else { var targets = creep.room.find(FIND_CONSTRUCTION_SITES); if(targets.length) { creep.moveTo(targets[0]); creep.build(targets[0]); } } } if(creep.memory.role == 'guard') { var targets = creep.room.find(FIND_HOSTILE_CREEPS); if(targets.length) { creep.moveTo(targets[0]); creep.attack(targets[0]); } }
-
RE: What is wrong with my script?
now with this code
~~~
var harvester = require('harvester');if (creep.memory.role == 'harvester')
{
if(creep.carry.energy < creep.carryCapacity) {
var sources = creep.room.find(FIND_SOURCES);
creep.moveTo(sources[0]);
creep.harvest(sources[0]);
}
else {
creep.moveTo(Game.spawns.Spawn1);
creep.transferEnergy(Game.spawns.Spawn1)
}
}for(var name in Game.creeps) {
var creep = Game.creeps[name];if(creep.memory.role == 'harvester') { harvester(creep); } if(creep.memory.role == 'builder') { if(creep.carry.energy == 0) { creep.moveTo(Game.spawns.Spawn1); Game.spawns.Spawn1.transferEnergy(creep); } else { var targets = creep.room.find(FIND_CONSTRUCTION_SITES); if(targets.length) { creep.moveTo(targets[0]); creep.build(targets[0]); } } }
}
if(creep.memory.role == 'guard') {
var targets = creep.room.find(FIND_HOSTILE_CREEPS);
if(targets.length) {
creep.moveTo(targets[0]);
creep.attack(targets[0]);
}
}
~~~
I get this error
[9:12:49 PM]TypeError: Cannot read property 'memory' of undefined
at main:3:10
at n:5:28406
at Object.c.runCode:5:34007 -
RE: What is wrong with my script?
it runs smoothly in main with no others put when I spawn this
~~~
Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Worker_Alpha', { role: 'harvester' } );
//then
Game.spawns.Spawn1.createCreep( [WORK, CARRY, MOVE], 'Builder_Alpha', { role: 'builder' } );
~~~
Worker_Alpha freezes
also I get an error saying harvester is not a function on line 5 and line 23 -
What is wrong with my script?
var harvester = require('harvester'); for(var name in Game.creeps) { var creep = Game.creeps[name]; harvester(creep); } if (creep.memory.role == 'harvester') { if(creep.carry.energy < creep.carryCapacity) { var sources = creep.room.find(FIND_SOURCES); creep.moveTo(sources[0]); creep.harvest(sources[0]); } else { creep.moveTo(Game.spawns.Spawn1); creep.transferEnergy(Game.spawns.Spawn1) } } var harvester = require('harvester'); for(var name in Game.creeps) { var creep = Game.creeps[name]; if(creep.memory.role == 'harvester') { harvester(creep); } if(creep.memory.role == 'builder') { if(creep.carry.energy == 0) { creep.moveTo(Game.spawns.Spawn1); Game.spawns.Spawn1.transferEnergy(creep); } else { var targets = creep.room.find(FIND_CONSTRUCTION_SITES); if(targets.length) { creep.moveTo(targets[0]); creep.build(targets[0]); } } } } if(creep.memory.role == 'guard') { var targets = creep.room.find(FIND_HOSTILE_CREEPS); if(targets.length) { creep.moveTo(targets[0]); creep.attack(targets[0]); } }