I'm a beginner in both javascript oop and game programming too(!) . Here i've created a game player with a method. but the method is returning undefined. why is that?,
bobsGame = {};
bobsGame.player = function(which){
this.which = which;
this.rollDice = function () {
diceVal = Math.floor(Math.random() * 6 + 1);
console.log(diceVal);
return diceVal;
}
}
var player1 = new bobsGame.player('player1');
and then in the markup…
$('#roll-dice-btn-1').click(function(){
bobsGame.player1.rollDice();
});
bobsgame.player1for example ? Can you build a working fiddle demonstrating your problem ?