# Reading 'isVector' unhandled error

**URL:** <https://discourse.codecombat.com/t/reading-isvector-unhandled-error/33123>\
**Category:** Bugs\
**Created:** [June 8, 2022, 4:21pm UTC](https://discourse.codecombat.com/t/reading-isvector-unhandled-error/33123 "2022-06-08T16:21:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![moonwatcher348](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/moonwatcher348/32/24126_2.png) [@moonwatcher348](https://discourse.codecombat.com/u/moonwatcher348)\
**Post date:** [June 8, 2022, 4:21pm UTC](https://discourse.codecombat.com/t/reading-isvector-unhandled-error/33123/1 "2022-06-08T16:21:52Z")

</div>

My code has an error that it didn’t have before:  
 ![Screenshot 2022-06-08 11.19.00](https://us1.discourse-cdn.com/flex016/uploads/codecombat/original/3X/3/c/3c3d372c14c17196148bf7fd4d33c0709958d934.png)  
I don’t understand where I give an undefined value in the functions, I always check if the object exists… I know this error comes from internal code somewhere, but I don’t understand where it could be trying to read an undefined value

```javascript
hero.isAbleToAttack = function (enemy) {
    return hero.isPathClear(hero.pos, enemy.pos);
};
hero.findEnemiesInSight = function () {
    let enemies = [];
    for (let enemy of hero.findEnemies()) if (hero.isAbleToAttack(enemy)) enemies.push(enemy);
    return enemies;
};
hero.findLowestFriend = function () {
    let friends = hero.findFriends();
    let lowestFriend = friends[0];
    for (let friend of friends) if (friend.health < lowestFriend.health) lowestFriend = friend;
    return lowestFriend;
};
hero.cast("gold-shield", hero.findByType("paladin")[0]);
while (true) {
    let enemy;
    enemy = hero.findNearest(hero.findByType("catapult"));
    if (!(enemy)) enemy = hero.findNearest(hero.findEnemiesInSight());
    if (enemy && hero.isPathClear(hero.pos, enemy.pos)) {
        if (hero.distanceTo(enemy) <= 3) hero.attack(enemy);
        else hero.move(enemy.pos);
    }
    if (hero.findEnemiesInSight().length === 0) hero.move({x: 78, y: 14});
    for (let friend of hero.findFriends()) {
        if (friend.findNearestEnemy() && friend.type == "soldier") {
            hero.command(friend, "defend", hero.findByType("archer")[hero.findByType("soldier").indexOf(friend)]);
            continue;
        }
        let friendEnemy;
        if (friend.type == "paladin" && friend.canCast("heal")) {
            let healTarget = hero.findLowestFriend();
            if (healTarget.health < healTarget.maxHealth) {
                hero.command(friend, "cast", "heal", healTarget);
                continue;
            }
        }
        if (friend.type == "paladin") friendEnemy = friend.findNearest(hero.findByType("witch"));
        if (!(friendEnemy)) friendEnemy = friend.findNearest(hero.findByType("skeleton"));
        if (!(friendEnemy)) friendEnemy = friend.findNearest(hero.findByType("ogre"));
        if (friendEnemy) hero.command(friend, "attack", friendEnemy);
        else {
            if (friend.pos.x < 43) hero.command(friend, "move", {x: 43, y: 59});
            else if (friend.pos.x < 50) hero.command(friend, "move", {x: 50, y: 58});
            else if (friend.pos.y > 39 && friend.pos.x <= 55) hero.command(friend, "move", {x: 50, y: 39});
            else if (friend.pos.x < 78) hero.command(friend, "move", {x: 78, y: 40});
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![NezyPlayz\_3102](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/nezyplayz_3102/32/28856_2.png) [@NezyPlayz\_3102](https://discourse.codecombat.com/u/NezyPlayz_3102)\
**Post date:** [June 8, 2022, 9:36pm UTC](https://discourse.codecombat.com/t/reading-isvector-unhandled-error/33123/2 "2022-06-08T21:36:43Z")

</div>

That happens to me sometimes, too. Maybe @Chaboi_3000 can help you or CodeCombat staff.
