IamThatGuy Posted July 8, 2015 Share Posted July 8, 2015 Some snippets from code: (stripped out stuff to see where issue is unrelated to issue) Shows how I am declaring, assigning and calling the arrays.. I am thinking the problem is the declaring of the array. I believe all my values in the 2nd dimension of the array is ALL referencing the same value. Declaring is first few lines posted below. var Board = function(){//varsvar board = []; //tried var board = new Array(8,8); for(var i = 0; i < 9; i++){board[i] = [];} //load board information from datathis.loadBoard = function(data){//stripped vars player and playerID //do something with k or data... $.each( data, function( key, val ) {$.each( val, function( kk, vv ) { //if no player yet, set as player 1if(playerID == 0){player = key;playerID = 1;}else if(player != key)//set as player 2{player = key;playerID = 2;} //Log is Correct, shows each x, y pass different value console.log("setting: x: " + vv.x + " y: " + vv.y + " result: " + vv.piece);board[vv.x, vv.y] = new Piece(vv.piece, playerID);});}); } this.renderPieces = function(){//2 for loops to cycle threw 2d array stripped, if( typeof board[x, y] != "undefined") //neglected{console.log("x: " + x + " y: " + y + " result: ");board[x, y].renderPiece( ((x*80)+35), ((y*80)+35) ); //renders same piece}}} var Piece = function(piece_, color_){//varsvar color = color_;var piece = piece_; var pieces = new Image();pieces.src = "resources/pieces.png"; this.renderPiece = function(x, y){ var x_offset = 0;var y_offset = 0; //greenif(this.color = 2){y_offset = 71;} switch(piece){case "a": x_offset = 340;break;case "b": x_offset = 68;break;case "c":x_offset = 136;break;case "d":x_offset = 204;break;case "e":x_offset = 272;break;} context.drawImage(pieces, x_offset, y_offset, 71, 68, x, y, 71, 68); } this.getColor = function(){return color;} this.getPiece = function(){return piece;} Edit: thats a little upsetting. I forgot to close the code tag and my post lost all formatting of code.. And I had to click indent over and over for nice formatting since the formatting didnt keep when copying out of my editor.. Quote Link to comment Share on other sites More sharing options...
IamThatGuy Posted July 8, 2015 Author Share Posted July 8, 2015 eh.. /me slaps self I dont know what language I was trying to use doing this: board[x, y] hehe.. board[x][y] is it.. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.