CodeCombat - Recruiting queue Help

I need help with this lvl, can someone tell me what l am doing wrong?

// Call peasants one after another.

// Neutral units are detected as enemies.
while(true) {
var neutrals = hero.findEnemies();
if(neutrals) {
hero.say(neutrals.id);
} else {
hero.say(“Nobody here”);
}
// Reassign the neutrals variable using findEnemies()
hero.findEnemy();
}

Line 7: say’s argument message shoulde have type string, but god null. Say what?

1 Like

Hey! It really helps if you format your code, do this by highlighting your code, and pressing the " < / > " button in the menu while you type!

1 Like

Well, neutrals is a list, so neutrals.id does not exist. You have to use the first name from that list: use an index.

Further on, you have a hero.findEnemy() statement, which is again incorrect and incomplete. It should be an assignment, like neutrals = hero.findEnemies() (not findEnemy) if it’s needed at all.

Cheers

ps: oh yes, and next time format your code properly, between three backticks, as described in the FAQ

1 Like

Sorry, l am new. Don’t know rules, yet.

Ok, Think l get it, but l don’t what to write in hero.say(?).
I did it when it come to names, but not in order, one after another. So, peasants get angry.
Can you tell me what exactly can l do about that.

PS. English is not my native language, I probably made some mistakes. I hope you can understant me well.

1 Like

Use:

hero.say(neutrals[0].id);

And probably replay a few levels, to understand the concept.

1 Like

I still don’t get why I’m not saying the neutrals name. here is my code.

// Call peasants one after another.
// Neutral units are detected as enemies.
var neutrals = hero.findEnemies();
while (true) {
    if (neutrals.length) {
        // Say the first unit in the neutrals array
        hero.say("message");
    } else {
        hero.say(neutrals[0].id);
    }
    // Reassign the neutrals variable using findEnemies()
    var enemies = hero.findEnemies();
}

I have tried hero.say() many different ways and i still never say anything other than "nobody to bump my gums at"
1 Like

I try it befor and don’t do anything, just go on else statement.
Thanks anyway, l will try to go back and understend better, or rest some
time of coding.

1 Like