Closed 383366204 closed 6 years ago
Hello @383366204! warrior.feel()
returns a space, so it's correct calling .getUnit()
on it. However, not all spaces have units on them. You should check if there is a unit before trying to call methods like .isFriendly()
on them.
const unit = warrior.feel().getUnit();
if (unit && unit.isFriendly()) {
warrior.rescue();
}
// OR:
const space = warrior.feel();
if (space.isUnit() && space.getUnit().isFriendly()) {
warrior.rescue();
}
P.S.: When reporting a problem, please try to follow the issue template and provide the data requested in it.
I think, essentially - The docs of the 'APIs' provide no clear idea of these two relationships to the player/warrior
const unitAPIObject = warrior.feel().getUnit();
const spaceAPIObject = warrior.feel();
It would be even clearer to just put in the instructions that
const space = warrior.feel();
const unit = space.getUnit();
With the inability to log anything to the terminal, it is almost impossible to intuit this.
what's wrong with people ? P.S.: When reporting a problem, please try to follow the issue template and provide the data requested in it.
, love issue_templates, why not using ? xDDDD @383366204 @olistic
@r-i-c-h I'll see what I can do to make that clearer.
With the inability to log anything to the terminal, it is almost impossible to intuit this.
This should be possible with warrior.think('<your message here>')
starting with v0.3.0.
The Space API and Unit API docs are now enhanced with @r-i-c-h's suggestions.
i read you documentation --> unit.isFriendly() so I wrote this:
but the terminal show: Invalid submitted code: Cannot read property 'isFriendly' of undefined
My English is not good , can you tell me how to get the unit. thanks