question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get an unit?

See original GitHub issue

i read you documentation --> unit.isFriendly() so I wrote this:

let unit = warrior.feel().getUnit();
    if(unit.isFriendly()){
      warrior.rescue();
    }

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

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
r-i-c-hcommented, May 19, 2018

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.

2reactions
olisticcommented, May 18, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unit Vector- Definition, Formula, Example and Solved ...
To find a unit vector with the same direction as a given vector, we divide the vector by its magnitude. For example, consider...
Read more >
Unit Vector - Formula, Definition, Caculate, Notation
To find a unit vector with the same direction as a given vector, simply divide the vector by its magnitude. For example, consider...
Read more >
How to Buy a Multi-Unit Property
How to Buy a Multi-Unit Property. Purchasing a multi-unit building is a first step for some individuals seeking to start a real estate...
Read more >
Unit Testing Tutorial: 6 Best Practices to Get Up To Speed
If you write code that stuffs things into a database or that reads a file from disk, you have not written a unit...
Read more >
How to get the unit test method name at runtime from within ...
If you are using NUnit 2.5.7 / 2.6 you can use the TestContext class:
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found