0

Not the greatest title i know, alright, consider:

for (var i = 0; i < map.length; ++i) {
place_ore(mountain_ore,mountain_allowed_ores) 
}

And inside place_ore(), I am trying to access map[i];, however when I try to do this, it gives me an undefined error. I think it has something to do with scope, but I can't quite work it out myself, any ideas?

Thanks.

2
  • 1
    i doesn't exist inside the function..you can always pass i in as another variable. Commented Sep 15, 2014 at 14:44
  • What's the definition of the function place_ore? Does it allow a third parameter? Commented Sep 15, 2014 at 14:46

1 Answer 1

3

You need to pass it in:

for (var i = 0; i < map.length; ++i) {
    place_ore(mountain_ore,mountain_allowed_ores, map[i]) 
}

And of course, modify your function signature:

function place_ore(mountain_ore,mountain_allowed_ores, mapTile) {
   //..place some ore in mapTile instead of map[i]
}
Sign up to request clarification or add additional context in comments.

1 Comment

Wonderful, I didn't think about passing it using place_ore() - well, thank you tonnes!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.