2016-07-22 18 views
0

Called Funktion:console.log gibt korrekte Ausgabe aber als Sollwert Zugriff gibt es falsch Ausgang

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

Aufruf Funktionsteil:

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]); 
        } 
       } 
      } 

Ich habe Funktion als Aufruf Funktion auch genannt wird hinzugefügt, wenn Schleife als aufrufende Funktion ist zu groß. Ich weiß, dass das berüchtigte Javascript-Loop-Problem ist. Ich benutze gc-devkit game engine, was neu und neu für mich ist. Ich habe das gleiche Problem für UIImage darin gelöst, indem ich eine benutzerdefinierte Klasse erstellt habe, aber hier brauche ich kein benutzerdefiniertes Array dafür. Kann mich jemand durch dieses Problem führen? Danke im Voraus.

Antwort

1

Sie verwenden j als Ihre Schleifenvariable beim Iterieren über TempSet, aber verwenden Sie i beim Abrufen von Elementen aus TempSet. Vielleicht nur

ändern
var tempSetEntry = tempSet[i]; 

zu

var tempSetEntry = tempSet[j]; 
+0

Thank you very much! Es war ein kleiner und dummer Fehler. – Renaissance

+0

Froh, es hat funktioniert! – Davis