Dungeon Arena: Coding problems

I’m not sure if this is a bug, or I just have issues with my code.

On the level tutorial, and the regular Dungeon Arena level, playing as a human, I have some problems:

The first is that the code: self.distance(enemy) allways gives me this error message:
time 0.1: Find the distance to a target unit.

I can see that the “enemy” object is initalized, and has the type munchkin, it was created with this method:
enemy = self.getNearest(enemies)

My second problem is with the librarian unit, I can’t cast spells on other units, because this code:
if self.canCast(“slow”, enemy): self.castSlow(enemy) Gives me this error:
time 0.1: Target must be a unit

This is my full code:

friends = self.getFriends()
enemies = self.getEnemies()
if enemies.length is 0:
    return  # Chill if all enemies are dead.

enemy = self.getNearest(enemies)
friend = self.getNearest(friends)

distanceFromFriend = friend.pos.x - self.pos.x
distanceFromEnemy = enemy.pos.x - self.pos.x

if distanceFromFriend < distanceFromEnemy and friend.type != "base":
    if self.canCast("haste", self.getNearest(friends)): 
    elif friend.health < friend.maxHealth:        
        if self.canCast("regen", friend): self.castRegen(friend)
    if self.canCast("slow", enemy): 

Also I couldn’t use the beneficial spells, my nearest “friend” is my base, is that expected?

Thanks for the help!

1.Distance Function


will give you an error because at time 0.1 the variable enemy will be NULL.So you are saying find distance to NULL.So check if the enemy is present and then call the distance function

if enemy
    dist = self.distance(enemy)

2.Enemy == NULL

if self.canCast("slow", enemy): self.castSlow(enemy)

this will give you an error because at time 0.1 there is no enemy.the the variable enemy will be NULL.You you are technically saying cast slow on NULL. A proper way to do this would be

if self.canCast("slow", enemy) && enemy : 

3.If you are standing close to your base you base will be the closest friendly unit

Hope This Helped

1 Like

Thanks a lot!

That works!

I’ll need to learn more, keep getting blocked on the code but for other issues now. XD


I need help with that but in java