My code is
create:function(spawn,name,energy,data) { var partNum; var body = []; partNum = Math.floor(energy/250); for(var i = partNum;i > 0;i--) { body.push(WORK); body.push(CARRY); body.push(MOVE); body.push(MOVE); } body = body.sort().reverse() //console.log(body,name,JSON.stringify(data)) var ret = spawn.spawnCreep(body,name,{memory:data}); console.log(ret) return ret; }
It doesn't work and it returns ERR_INVALID_ARGS.
Also, in training room, it totally works!
- spawn is the structureSpawn object, object type
- name is name of creep, string type ex) "W0 Spawn1"
- data is memory of creep, object type ex) {role:"harvester"}
- energy is the usable energy to spawn creep, int type
- body is the creep's body array ex) [WORK,WORK,CARRY,CARRY,MOVE,MOVE,MOVE,MOVE]