Teleport lasso help CPP [SOLVED]

)

Try to replace hero.distanceTo with the variable of distance you defined at the start of your code.

I’ll try once I get back home. I feel like I tried that though. I will post an update in 10 hours.

I wanted @johny_johny to take care of distance by himself))

It’s a complete waste of time to test programs, then wonder how to say what you did without giving the finished code and finally no one reads you … It’s not for the first time …

@xython I completely missed your original point of moving the “IF” statement and corrected that. That was 100% it. Just needed to move it. Sorry for missing that.
@Alexbrand Thanks for helping. I am dense I guess. haha

I have been doing this for about a week now. Can one of you explain to me why That matter so much?
My understanding is.
line 2 should be able to be combined with line 4 and line 3 should be able to just sit on line 2.
Why does that not work? How come it just has my character running around ignoring the enemy.type portion? Does it end up ignoring the type if I combine it? Does it just ignore the type if I have distance calculated to soon? Like I said before I had both <> and it didn’t matter it attacked everything but soon as I moved the IF statement. Worked perfectly.

 auto enemy = hero.findNearestEnemy();<<<< finding closest enemy
        if (enemy) { <<<< if there is an enemy
        auto distance = hero.distanceTo(enemy); <<<< determining distance
        if (enemy.type == "munchkin" && distance < 20) { <<< combining the type and distance if you need to attack or not
            hero.attack(enemy);

Don’t think so, lack of skills maybe.
Besides I should apologize - I mislead myself and you a bit: I tried your code in JavaScript instead of C++( My fault(

Anyway I finally found the thing in your code. The main one is extra ; in line
if (enemy && enemy.type == "munchkin" && hero.distanceTo > 20); {
Takin it off, turnin > into < and hero.distanceTo into hero.distanceTo(enemy) made everything work.

It is sorted out. I needed to change my IF statement location as well. And moving the auto distance = hero.distanceTo(enemy);
After all the other corrections. That is what finally got my character to stop killing everything. Swapping 2 lines of code

A little bit tricky, but the level creator cheated with the burl in the right bottom corner
( good glasses here) there’s always a nearest enemy


that’s why the default code works


same thing but cheapest glasses - still (almost) works but throws an error
there’s good help - but who’s reading manuals these days :wink:

Ah, that explains it a bit and helps me understand. Thank you for clearing that up.