Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

Cannot read property 'value' of undefined


Before submitting to gitHub, I’d like to check first here. I decided to make two helper functions

function walkTo(positioned) {
    hero.moveXY(positioned.pos.x, positioned.pos.y);
function ifCollect() {
    var item = hero.findNearestItem();
    if (item) 

The first works directly in program, however the second one - ifCollect - raises a strange error on the “walkTo(item)” line:
Cannot read property ‘value’ of undefined

I’m pretty sure this looks like a bug but I’d like to check first.



  if (item) {
        walkTo(item); }


Thanky you, but this obviously does not help (I really tried, just to check) - JavaScript like all C-like languages expects a command after if, and if it is a single command, it does not require braces.


function walkTo(positioned) {
hero.moveXY(positioned.pos.x, positioned.pos.y);
} // why tou need it?

function ifCollect() {
var coin = hero.findNearestItem();
if (coin )
hero.move(coin.pos); //or hero.moveXY(coin.pos.x, coin.pos.y) );

  1. Is that important? This is a common language feature that is not working.
  2. It simplifies things - you simply write that function once, include into your library and use it for flag collection, coins collenction etc. etc.