Level: Emphasis on Aim

After a quick review of this Level, i noticed that the humans patrolling are on team Allies, whereas the tower is on team humans. therefore a condition such as " if (unit.team != this.team) " would result in killing everyone. Why are not the soldires on team human as well? I understand they are allies, but since they are the same faction…maybe they should be human as well? If you go for their speciffic team, it works just fine. Thank you. :slight_smile:

Kind of a hack so that the tower can hit those soldiers. If they were on the same team, the arrow would never hit. Probably need a non-hacky solution though, you’re not the first person to try that solution! And it should be a valid solution. Maybe this is a lesson in why hacks can go awry.

3 Likes

I am so confused on this level. The tower just stands there and says “All Clear” while the ogres walk right past it! I checked the hint and answer and they approximately match my code. Can someone please tell me where I am messing up?

Here is my code:

// The following runs whenever the tower needs
// something to do.

var unit = this.getNearestCombatant();
if ( unit && unit == “ogre”) {
this.say('Perish, ’ + unit.id + ’ of the ’ + unit.team);
this.attack(“unit”);
}
else {
this.say(‘All clear.’);
}

// This tower is too bloodthirsty!
// Have it check the unit’s team before opening fire.
// There are three teams: “ogres”, “allies”, and “humans”.
// If you need help, press Guide at the top.

Almost! Your code has this check:

if ( unit && unit == "ogre") {

This is checking of the unit itself is the string "ogre", when in fact the unit is a JavaScript object with many properties.

Instead, you’d need to check unit.team and compare it to "ogres" (plural). Hope this helps!

(This level could be a lot better with helping you figure this out.)

1 Like

I changed the code to this.

if ( unit && unit.team == “ogres”)

But it still doesn’t work. At the bottom it says “ReferenceError: ArgumentError not defined”

It is talking about Line 10, but I haven’t changed that while I was coding (it is still the original text). This is Line 10:

this.say(‘All clear.’);

EDIT: Nothing is wrong with line 10, it is talking about the whole code.

Hmm, that’s strange. Can you paste your multiplayer link? I can see what’s going on then.

Right here.

Oh, I see the problem now! I could have noticed this earlier. It should be this.attack(unit); instead of this.attack("unit");, since you’re attacking the unit local variable and not a string "unit". The ArgumentError bug is my bug–I’ll fix it straightaway! It should have given you a really helpful error message instead, but it didn’t know where to find it.

Thanks for the help, I appreciate it!

how come unit.id does not work unless it is in the if statement? You already got a reference to unit

Hi Scnoobi–can you post your multiplayer link so I can take a look? It’s possible a new transpiler bug with some security features I introduced to Aether.

Naah its fine i just tried to read .team out of null(unit.team) get typeError:P since its null until an combatant actually comes into range.

basically just my incompetence! i blame tiredness:D

By the way why is public and private and those things not taught?

JavaScript has no formal convention of public and private. That said, one of the things we’ve built for the multiplayer levels is the concept of each unit having an API, and only being able to publicly access the properties in that API. That should make levels like this a lot easier. It’s getting close to ready.

I got the code to basically work, but it only attacks one ogre:

// The following runs whenever the tower needs
// something to do.

var unit = this.getNearestCombatant();
if (unit && unit.team == “ogres”) {
this.say('Perish, ’ + unit.id + ’ of the ’ + unit.team + ‘!’);
this.attack(unit);
}
else {
this.say(‘All clear!’);
}

// This tower is too bloodthirsty!
// Have it check the unit’s team before opening fire.
// There are three teams: “ogres”, “allies”, and “humans”.
// If you need help, press Guide at the top.

I also noticed I can’t reverse the code to first check for allies and kill everything else. It doesn’t even say “All clear!” if it first spots an ally.

Any thoughts to what I might be missing?

I get the same issue with the tower just attacking one ogre. Probably due to the fact that one of the soldiers always walks tower-side of the ogre, preventing get.NearestCombatant from seeing the ogre.

Would be useful to know if there’s a ‘get next nearest’, or if there’s a solution to this issue.

Just made them all the same speed again. No idea how they got changed to all different speeds before. Thanks for detecting that one!