Don't know how to make tharin attack certain things in Dungeon Arena


this.findTypeInRange = function(units, type) {
    for (var i = 0; i < 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 thrower = this.findTypeInRange(enemies, "thrower", "spear");
var munchkin = this.findTypeInRange(enemies, "munchkin");

the this.findTypeInRange was something i saw in another post so i put it in but now i dont know how to make it work and the this.getNearestEnemy code is like bugged or something because when i do it tharin will target a unit but then when he gets close he’ll target another until he gets near the cave and stops and actaully hits something but by that point he is half dead already, and is swarmed i dont know why this happens but anyway i would like to figure ourt how to make him and other units target certain things and if not possible in dungeon arena i would like to start doing skyspan for more commands

Thanks in advance

i think the this.findTypeInRange is to check if there is a troop in range and attack it maybe

So far you aren’t telling Tharin to attack anything; is there more code that he’s using? Once you find if there is a shaman or brawler or thrower or munchkin, you might have to attack it if it exists. The findTypeInRange function that you have tried doesn’t find the nearest unit, though, so it may be finding ones that are further away and going to chase them.

Tharin’s attackRange is very short, though, so this probably won’t find any enemies to attack. You might want to change this.attackRange to 10 to make him chase something that’s pretty close.

Ok thanks so much for telling me about the this.findTypeInRange that will help so much and the reason i dont have an attack code is because, now i know this, the this.findTypeInRange code was messing it up

btw i think ill be using sky span because it has more commands which unlocks more options
i would like to know if there is a way to cancel a code until a certain amount of time because i want to build a lot of units before the hero so i dont waste all my gold in the beggining

Try something like this:

if ( > 10) {
    // Do this stuff only after the world has been running for 10 seconds.
    // ...