d-pollard / Pokemon-GO-node-api

Pokemon Go! Node API library
MIT License
16 stars 4 forks source link

Error in exampleFort.js (Fix Included) #7

Closed ButchMonkey closed 8 years ago

ButchMonkey commented 8 years ago

There are 2 nested loops in exampleFort.js -

...
for (var i = hb.cells.length - 1; i >= 0; i--) {
        // console.log(hb.cells[i])
        console.log(i)
        if(hb.cells[i].Fort) {
            var currentFortArr = hb.cells[i].Fort;
            for (var i = currentFortArr.length - 1; i >= 0; i--) {
                var currentFort = currentFortArr[i];
...

The outer for loop will only iterate once due to the reuse of "i" as a loop variable. Please change this to something else to fix. Thanks :)

Example.

...
for (var i = hb.cells.length - 1; i >= 0; i--) {
        // console.log(hb.cells[i])
        console.log(i)
        if(hb.cells[i].Fort) {
            var currentFortArr = hb.cells[i].Fort;
            for (var j = currentFortArr.length - 1; j >= 0; j--) {
                    var currentFort = currentFortArr[j];
...
ButchMonkey commented 8 years ago

Also, there is no handle for an undefined response in getFort()

d-pollard commented 8 years ago

Good catch, Ill check it out and change it! Unless you'd like to make a pull request

ButchMonkey commented 8 years ago

I'll let you patch it :) Might do a pull request once I finish upgrading my copy of the fort scanning

d-pollard commented 8 years ago

Sweet! Looking forward to it

d-pollard commented 8 years ago

I pushed a fix out for it - thanks for the catch!