JavaScript won't add values to array -
i have written script returns values. when log variable containing values, shows them, , correct. then, no matter how try, concat, push, equals, etc. when attempt add values array, log contents of array, values not there or undefined. here code, or @ least subset of it.
displayrange: function () { if( app.selectedobject !== undefined && app.selectedobject.movement !== undefined && app.selectactive === undefined ) { // holds rage t.rarray = []; t.oarray = []; app.selectactive = true; t.obj = app.selectedobject; // amount of allotted movement unit t.len = t.obj.movement * 2; // loop through x , y axis ( x = -t.len; x < t.len; x += 1){ ( y = -t.len; y < t.len; y += 1 ){ // return cost of each movement t.hl = this.calcrange('x', x, y ); // if movement cost less or eual allotted movement add range array if ( t.hl.move <= t.obj.movement ){ // find obsticles t.ex = t.hl.origin.x + x; t.wy = t.hl.origin.y + y; t.obsticle = this.findobsticles(t.ex, t.wy); // number of offset movement obsticle if ( t.obsticle !== undefined ){ t.offset = app.settings.obsticlestats[t.obsticle.obsticle][app.selectedobject['type']]; if ( t.offset !== undefined ){ // make array of offset values, starting point, plus movement, , amount of offset beyond movement t.oarray.push(this.obsticlelogic( t.ex, t.wy, t.mx, t.my, t.offset )); } } // add values array t.rarray.push({ x: t.ex, y: t.wy, type:'highlight'}); } } } offsetarr = app.offsetarray( t.rarray, t.oarray ); ( l = 0; l < offsetarr; l += 1 ){ app.map.highlight.push(offsetarr[l]); } ( = 0; < t.oarray.length; += 1 ){ app.offset.push(t.oarray[x]); } console.log(t.oarray); console.log(offsetarr); console.log('offset:'); console.log(app.offset); console.log('highlight'); console.log(app.map.highlight); window.requestanimationframe(app.animateeffects); } return false; }, i have set app.map.highlight = []; in app.map area. same app.offset.
they have been declared, in different object.
i can't understand why won't add values array. log them , see them, directly after call array push, , sets undefined. why happen?
the reason being looped through try , them array because that's last thing tried.
i believe had issue conflicting variable names, renamed of them , started working.
Comments
Post a Comment