Can't Find Error.



  • I have been playing Screeps and whilst adding code to my main module, I got the above error. Unfortunately, Screeps doesn't tell you the location of an error like this, and I can't find anything. From my knowledge, the issue is that there is a bracket that is either missing or not supposed to be there. But as I said I can't see anything. Below is the code in question.

    var canspawnSmall = Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, CARRY, MOVE, MOVE], 
    'Worker1', { dryRun: true });
    var canspawnBig = Game.spawns['Spawn1'].spawnCreep([WORK, WORK, CARRY, CARRY, MOVE, MOVE], 
    'Worker1', { dryRun: true });
    var harvesters = _.filter(Game.creeps, (creep) => creep.memory.role == 'harvester');
        console.log('Harvesters: ' + harvesters.length);
    var builders = _.filter(Game.creeps, (creep) => creep.memory.role == 'builder');
        console.log('Builders: ' + builders.length);
    var upgraders = _.filter(Game.creeps, (creep) => creep.memory.role == 'upgrader');
        console.log('Upgraders: ' + upgraders.length);
    var repairers = _.filter(Game.creeps, (creep) => creep.memory.role == 'repairer');
        console.log('Repairers: ' + repairers.length);
    var attackers = _.filter(Game.creeps, (creep) => creep.memory.role == 'attacker');
        console.log('Attackers: ' + attackers.length);
    
    if (harvesters.length < 2) {
        if (harvesters.length < 2 && canspawnBig == 0) {
            Game.spawns['Spawn1'].spawnCreep([WORK, WORK, CARRY, CARRY, MOVE, MOVE], 'Harvester' + Game.time, {memory: {role: 'harvester'} });
        } elif (harvesters.length < 2 && canspawnSmall == 0) {
            Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, CARRY, MOVE, MOVE], 'Harvester' + Game.time, {memory: {role: 'harvester'} });
        }
    } elif (harvesters.length >= 2 && upgraders.length < 2) {
        if (upgraders.length < 2 && canspawnBig == 0 ) {
            Game.spawns['Spawn1'].spawnCreep([WORK, WORK, CARRY, CARRY, MOVE, MOVE], 'Upgrader' + Game.time, {memory: {role: 'upgrader'} });
        } elif (upgraders.length < 2 && canspawnSmall == 0 && canspawBig != 0) {
            Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, CARRY, MOVE, MOVE], 'Upgrader' + Game.time, {memory: {role: 'upgrader'} });
        }
    } elif (harvesters.length >= 2 && upgraders.length >= 2 && builders.length < 2) {
        if (builders.length < 2 && canspawnBig == 0) {
            Game.spawns['Spawn1'].spawnCreep([WORK, WORK, CARRY, CARRY, MOVE, MOVE], 'Builder' + Game.time, {memory: {role: 'builder'} });
        } elif (builders.length < 2 && canspawnSmall == 0 && canspawnBig != 0) {
            Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, CARRY, MOVE, MOVE], 'Builder' + Game.time, {memory: {role: 'builder'} });
        }
    } elif (harvesters.length >= 2 && upgraders.length >= 2 && builders.length >= 2 && repairers.length < 2) {
        if (repairers.length < 2 && canspawnBig == 0) {
            Game.spawns['Spawn1'].spawnCreep([WORK, WORK, CARRY, CARRY, MOVE, MOVE], 'Repairer' + Game.time, {memory: {role: 'repairer'} });
        } elif (repairers.length < 2 && canspawnSmall == 0 && canspawnBig != 0) {
            Game.spawns['Spawn1'].spawnCreep([WORK, CARRY, CARRY, MOVE, MOVE], 'Repairer' + Game.time, {memory: {role: 'repairer'} });
        }
    } else {
        console.log('All Set Chief')
    }
    console.log('Can Big:' + canspawnBig)
    console.log('Can Small:' + canspawnSmall)


  • Good evening (or morning)

    What error exactly? I don't see one posted in your question.

    Also, would highly recommend joining the Discord for Screeps there's a #world-help section that folks help people out in. Its a bit more dynamic and faster responses than the forums.

    I would say elif may be causing the issue if your doing JavaScript I'm not sure that works off-hand, looks like its a short for else if in python? Some people do play in python, there's a channel dedicated to it in the discord as well.