Teleport lasso help CPP [SOLVED]

Okay, so I have made multiple tiny changes. This is what I ended with.
Yet, my character ATTACKS EVERYTHING! Straight murders the field. I don’t understand why.

int main() {
    while (true) {
        auto enemy = hero.findNearestEnemy();
        auto distance = hero.distanceTo(enemy);
        // If enemy.type is "munchkin"
        // AND the distance to it is less than 20m
        if (enemy && enemy.type == "munchkin" && hero.distanceTo > 20); {
            // Then attack it.
    return 0;

on line 7 after the comments I even took away the beginning portion enemy && leaving just enemy.type == "munckin".
 Yet, because of the && hero.distanceTo > 20 portion.
 My character attacks everything!
Not just everything within a range of 20 but everything on the map outside of the range as well.

hmmm, I do python, but

// distance to it is less than 20m
if hero.distanceTo < 20 
// wrong sign? < is less than, > is greater than

Also, I think that hero.distanceTo should be distance because you defined the variable distance, but hero.distanceTo is a function.

I have had both signs as greater and less and changing it to just distance. Same thing happens.
but putting it as < 20 and distance. Character still murders everything and dies half way though

This is a subscriber only level, so I can’t test it and see what is going on. Maybe someone else can help, but that is about as much as I know that doesn’t look right. :cry:

thanks for trying at least

        auto enemy = hero.findNearestEnemy();
        if (enemy){
           float distance = hero.distanceTo(enemy);
           if (enemy.type == "munchkin" &&  distance < 20)
            // Then attack it.

I don’t think the default code is perfect

I’m not skilled in JavaScript but maybe it’s in this part

hero.distanceTo > 20)

Try to change it to hero.distanceTo(enemy) < 20). Because looks like you don’t use variable you defined.

P.S. I cheked and tried level in Python with default code and writing two lines succeeded

if enemy and enemy.type=="manсhkn" and distance<20:

python default code:

while True:
    enemy = hero.findNearestEnemy()
    distance = hero.distanceTo(enemy)
    # If enemy.type is "munchkin"

can you find a distance to something that may not exist?
Because in CoCo python, cpp is javascript (ES5?) in disguise i also don’t know what happens in reality. There is something very murky in js Hoisting in JavaScript

Oh. Yeah, I struggled with this many times. But in this level enemy spawned right from the start and this doesn’t cause troubles.

@Alexbrand not using java. C++ also did nothing. Still attacks everything.

The whole code please)

go to top. its already posted.

Uhm, and no changes in code at this moment?

Changes that I have made but made no difference based on line 8.

if (enemy && enemy.type == "munchkin" && hero.distanceTo < 20);

turned it into BUT not limited too including adding
if ( enemy.type == “munchkin” && hero.distanceTo < 20);
if (enemy.type == “munchkin” && distance < 20);
if (enemy && enemy.type == “munchkin”);
if ( hero.distanceTo < 20);
if (enemy && enemy.type == “munchkin” && hero.distanceTo(enemy) < 20);

Putting this code (with reversing > to < ) gives me “Unexpected identifier” alert(

In the picture you dont have a beginning bracket { after int main()

Still the same

Interesting. I get nothing. Level possible broken???
Sorry for mobile picture away from computer currently

Well, I did it with default code + your two lines

if (enemy && enemy.type == "munchkin" && hero.distanceTo > 20); {

Changed only some synthax and put right variable.

so it works correctly without the hero.distanceTo?