Help for noobs (mainly me)


#1

So i am new to CodeCombat and the tutorial did nothing to help me in multiplayer so i have been doing the best i can to figure out how to wright and use the different codes/spells. Anyway so I use the guide in dungeon battle or whatever and use this code:

this.findTypeInRange = function(units, type) {
    for (var i = 0; 1 < units.length; ++i) {
        var unit = units[i];
        if (unit.type === type && this.distance(unit) < this.attackRange)
            return unit;
    }
    return null;
};
var enemies = this.getEnemies();
for(var i = 0; i < enemies.length; ++i) {
  var enemy = enemies[i];
}
var shaman = this.findTypeInRange(enemies, "shaman");
var brawler = this.findTypeInRange(enemies, "brawler");
var munchkin = this.findTypeInRange(enemies, "munchkin");
var thrower = this.findTypeInRange(enemies, "thrower", "spear"); 

and when i do the cast spell (btw this is on tharin) it says could not define ‘type’ and in the guide this is almost exactly how its written except for a couple of things. And i do not know how to define ‘type’ cause its nowhere in the guide and when i go the ‘type’ spell in the bottom all it says is this.type-string or something like that. So i need help if any of you veterens gan give me tips or help me with the problem at hand that would be very helpful thanks


#2

In the body of your function you have:

for (var i = 0; 1 < units.length; ++i) {

The condition 1 < units.length will always be true if units has more than one item. This will cause you to run over the end of the array. This probably means that unit ends up as undefined, so when you try to access unit.type, it blows up.

You probably meant to use i here.

I couldn’t see anything else obvious that would prevent your code from running but I just eyeballed it.

Happy dungeoneering!


#3

thanks it worked ill probably be back with more problems but this really helps