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); {
hero.attack(enemy);
// 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.
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.
auto enemy = hero.findNearestEnemy();
if (enemy){
float distance = hero.distanceTo(enemy);
if (enemy.type == "munchkin" && distance < 20)
// Then attack it.
}
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
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);