Saturday, 13 May 2017

that.init is not a function - Node.js

i am pretty much completely new to javascript and node.js, but im working on a Connect 4 robot project. For this purpose i am trying to get a code i found on the internet to work. This is the part im having problems with:

Game();

function Game() {
this.rows = 6; // Height
this.columns = 7; // Width
this.status = 0; // 0: running, 1: won, 2: lost, 3: tie
this.depth = 4; // Search depth
this.score = 100000, // Win/loss score
this.round = 0; // 0: Human, 1: Computer
this.winning_array = []; // Winning (chips) array
this.iterations = 0; // Iteration count

var that = this;

that.init();
}

Game.prototype.init = function() {
// Generate 'real' board
// Create 2-dimensional array   
var game_board = new Array(that.rows);
for (var i = 0; i < game_board.length; i++) {
    game_board[i] = new Array(that.columns);

    for (var j = 0; j < game_board[i].length; j++) {
        game_board[i][j] = null;
    }


}

When i try to run it with node.js, i get following error:

that.init();
     ^

TypeError: that.init is not a function
at Game (C:\Users\Kareem\Desktop\Neuer Ordner\connect-four.js:21:10)
at Object.<anonymous> (C:\Users\Kareem\Desktop\Neuer Ordner\connect-four.js:7:1)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:390:7)
at startup (bootstrap_node.js:150:9)    

What exactly is causing this error? Thanks in advance for your help!



via Kaza123

No comments:

Post a Comment