Renaissance Renaissance - 1 year ago 74
Javascript Question

Console.log gives correct output but when accessing set value it gives wrong output

Called Function:

this.findVerticalPossibleScoring = function(){
var possibilitySet = [];
for (var j = 0; j < 9;j++ ) {
for (var i = 0; i < 7; ){
var tempTile = this._tiles[i][j];
var tileTagValue = this.gameTilesValue[i][j];
if(this.gameTilesValue[i+1][j]==tileTagValue && this.gameTilesValue[i+2][j]==tileTagValue){
setElement = [];
var tempPoint = this.makeArray(i,j);
console.log(" verical i:"+i+" j:"+j);
i = i+1;
return possibilitySet;
this.makeArray = function (a,b){
console.log("element i:"+a+" j:"+b);
var arrayTemp = [];
return arrayTemp;

Calling function part:

if(scoringPossible == true){
//blast the tiles and add new tiles;
var verticalPossibleScoring = this.findVerticalPossibleScoring();
toBeDeletedTiles = [];
for(var i=0;i<verticalPossibleScoring.length;i++){
var tempSet = verticalPossibleScoring[i];
for(var j = 0;j<tempSet.length;j++){
var tempSetEntry = tempSet[i];
console.log("TILE i:"+tempSetEntry[0]+" j:"+tempSetEntry[1]);

I have added called function as well as calling function if loop as calling function is too big. I know this is infamous javascript loop issue. I am using gc-devkit game engine which is new and I new to it. I had solved the same issue for UIImage in it by creating custom class, but here I don't require custom array for it. Can any one guide me through this issue. Thanks in advance.

Answer Source

You use j as your loop variable when iterating over tempSet but then use i when getting elements from tempSet. Maybe just change

var tempSetEntry = tempSet[i];


var tempSetEntry = tempSet[j];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download