Navigation

    forum

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

    cjmoto7

    @cjmoto7

    2
    Posts
    639
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    cjmoto7 Follow

    Posts made by cjmoto7

    • RE: tower.attack is not a function...???

       Ah good point! Next time that will be the first thing I do haha

      when I console logged tower, it returned every structure I have, then I noticed var towers = _.filter(Game.structures, (s) => STRUCTURE_TOWER); was missing something.

      Changed it to this:

      var towers = _.filter(Game.structures, (s) => s.structureType == STRUCTURE_TOWER);

      and now everything works like a charm!

      Thanks!

      posted in Help
      cjmoto7
    • tower.attack is not a function...???

      // Handle repairing and attacking for towers
      var towers = _.filter(Game.structures, (s) => STRUCTURE_TOWER);
      for (let tower of towers) {
      var closestWounded = tower.pos.findClosestByRange(FIND_MY_CREEPS, {
      filter: (w) => w.hits < w.hitsMax
      });
      var closestHostile = tower.pos.findClosestByRange(FIND_HOSTILE_CREEPS);
      var closestDamagedStructure = tower.pos.findClosestByRange(FIND_STRUCTURES, {
      filter: (s) => s.hits < s.hitsMax && s.structureType != STRUCTURE_WALL
      });
      if(closestHostile) {
      tower.attack(closestHostile);
      }
      if ((closestWounded) && (tower.energy > 250)) {
      tower.heal(closestWounded);
      }
      /*if ((closestDamagedStructure) && (tower.energy > 990)) {
      tower.repair(closestDamagedStructure);
      }*/
      }

      This is all my code related to towers, I'm stumped as to why I keep getting this "TypeError: tower.attack is not a function
      at Object.module.exports.loop (main:74:8)
      at __mainLoop:1:52"
      In my emails whenever an npc creep comes and wipes out my colony (well it wouldn't if my tower was working)
      tower.repair() works just fine, so I can't understand why this error is showing.

      Any help would be greatly appreciated!

      PS: line 74 is tower.attack(closestHostile);
      PPS: don't mind the commented out repair section, still working on making it periodic

      posted in Help
      cjmoto7