Navigation

    forum

    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    1. Home
    2. Draoi
    3. Topics
    • Flag Profile
    • block_user
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Groups
    • Blog

    Topics created by Draoi

    • Unexpected token {
      Help • • Draoi

      5
      5
      Posts
      9839
      Views

      I'd also restructure it, it is too WET right now, you want your code DRY One might argue that Game.spawns.Spawn1.createCreep is only one line, but this is a function call, that you WILL change as your screeps empire grows, you'll heave more than one spawn, createCreep may not succeed and you'd want to fall back to another one. So I'd split this loop to two logical sections 1)Pick creep 2)Create creep Code becomes: ```javascript //Select what to build var creepBody = null; var creepMemory = null; if (guards < 4){ creepBody = guard; creepMemory = {role:"guard"} }else if (medics < 3){ creepBody = medic; creepMemory = {role:"medic"} } ... //Build Game.spawns.Spawn1.createCreep(creepBody, null, creepMemory); //easy to replace the createCreep call, fall back when it fails, etc. //Now, let's get more javascriptey:) var creepSetupsByRole = { "guard" : { "min": 4, "body": [ATTACK, ATTACK, MOVE], "max": 10, "curr": 0, "roleName" : 'guard', "essential" : true //Do not try to build others unless have enough of this role }, "medic" : { "min": 4, "body": [HEAL, HEAL, MOVE], "max": 10, "curr": 0, "roleName" : 'medic' }; //Count the current number of creeps with given role here. //Possibly sort roles by priorities for (var roleName in creepSetupsByRole){ var currRoleSetup = creepSetupsByRole[roleName]; if (currRoleSetup.curr < currRoleSetup.min){ var buildResult = tryBuildCreep(currRoleSetup); if (!(buildResult < 0) && !currRoleSetup.essential){ // break; } } } function tryBuildCreep(creepSetup){ return Game.spawns.Spawn1.createCreep(creepSetup.body, null, {role: creepSetup.roleName}); }
    • Email notifications about game errors
      Technical Issues and Bugs • • Draoi

      2
      2
      Posts
      3583
      Views

      I also am having this issue. For added context, the error is the same for me each time as well: 'TypeError: Cannot read property 'length' of undefined'
    • if (''role' > 6)
      Help • • Draoi

      3
      3
      Posts
      4351
      Views

      Thank you, I failed to catch that!
    • Get number of creeps with "x" role
      Help • • Draoi

      9
      9
      Posts
      18545
      Views

      Oh dear. I actually, even after copy/pasting it into here, failed to realize i left role: 'x' in there. Meant to change that to harvesters. Thanks for your help, it finally works. I checked the memory, I had over 202 creeps spawn since I started it, which was hours ago and even running on 500% speed, it was still taking between 5-10 seconds per tick. There were easily over 100 creeps on screen. SO. MANY. HARVESTERS.