If more than so many enemies

Hello, I’m trying to work out a way to do things, such as cleave if there are more than so many enemies.

I know how to get it done if enemies are near or far, but I’m wanting to do something such as “cleave” or other abilities if there are more than say 3 or 5.

I found a similar topic, but the answer just said have better glasses. I have some decent glasses, and the ones that were mentioned in the other post, but I still cannot figure this out.

Thanks for your help ahead of time!


loop over list of enemies
    if enemy within cleave distance
        increment count

if count high enough
    perform high enemy count action
1 Like

Thanks! That will help.

I tried this, but for some reason my counter either doesn’t resolve anything or it resolves as NaN

snippet below:

    munchkins = self.findByType("munchkin")
    for munchkin in munchkins:
        if self.distanceTo(munchkin) < 10:
            numberCloseMunchkins += 1
            self.say(numberCloseMunchkins + " munchkins are nearby!")

this will output NaN munchkins are nearby.

Obviously, it won’t cleave them either because the if statement will never resolve true.

What am i missing here?

I tried setting numberCloseMunchkins to 0 by default, but that didn’t solve the problem either.

I found the problem, i used == instead of = to set the initial value.