Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by MikeL

This was particularly insidious. But maybe if I had made better use of the console, I would have found it more quickly. Here is the problem:

If you do something like this:
var myArr = [[1,3,5],[7,9,11]];
console.log(myArr);
ig.game.spawnEntity( EntityOdd, 50, 50, {numArr: myArr} );

You will get this ouput to the console, as expected:
[ Array[3] , Array[3] ]

But, let&039;s say you now want to access numArr from within your EntityOdd. From within EntityOdd doing #console.log(this.numArr) gives you this:
[ Object , Object ]

For some reason the nested arrays get changed into generic objects. As a workaround I did this for now:
var myArr = [[1,3,5],[7,9,11]];
var entity = ig.game.spawnEntity( EntityOdd, 50, 50, {numArr: myArr} );
entity.numArr = myArr;

and it seems to work. Interestingly using a non-nested array like just [1,3,5,7,9,11] works just fine.

1 decade ago by MikeL

Update:
I created a fix for this. Within ig.merge I changed within the else portion:

else {
    if( !original[key] || typeof(original[key]) != 'object' ) {
        if (ext.constructor === (new Array).constructor){
            original[key] = [];
        }else{
            original[key] = {};
        }
    }
    ig.merge( original[key], ext );
}

This seems to work for both nested arrays and other objects. I even tried triple nesting arrays with objects inside and it works, so far as I can tell...

Working through that recursion sure did give me a headache though :P

1 decade ago by dominic

Quote from MikeL
Working through that recursion sure did give me a headache though :P

You're not the only one ._.

Thank you so much for the bug report and fix!
Page 1 of 1
« first « previous next › last »