jjwallace Posted April 8, 2017 Share Posted April 8, 2017 This might be a stupid question but for some reason, my brain is broken today. I have a game state that adds a new object and calls a function on it. BasicGame.Game.prototype = { create: function () { var levelController = new LevelController(this, playerType); var playerType = 3; levelController.makePlayer(playerType); }, createPlayer: function (playerType) { console.log('Player ' + playerType + ' created'); } } I want to access a function from game state. var LevelController = function (superThis) {}; LevelController.prototype = {} LevelController.prototype.makePlayer= function(superThis, playerType){ superThis.createPlayer(superThis, playerType){ } Uncaught TypeError: BasicGame.Game.makePlayer is not a function at creatPlayer Link to comment Share on other sites More sharing options...
samme Posted April 8, 2017 Share Posted April 8, 2017 18 minutes ago, jjwallace said: Uncaught TypeError: BasicGame.Game.makeFish is not a function at InitFish Where is this code though? Link to comment Share on other sites More sharing options...
jjwallace Posted April 9, 2017 Author Share Posted April 9, 2017 Oops my mistake, that code isnt part of the problem, i forgot to rewrite the error... fixed Link to comment Share on other sites More sharing options...
samme Posted April 9, 2017 Share Posted April 9, 2017 You can save the instantiated LevelController on the game or the current state, something like (abbreviated) var LevelController = function (superThis) {}; LevelController.prototype = {}; // … BasicGame.Game.prototype = { create: function () { this.game.levelController = new LevelController(this, playerType); this.game.levelController.makePlayer(playerType); // … } // … }; Link to comment Share on other sites More sharing options...
jjwallace Posted April 10, 2017 Author Share Posted April 10, 2017 var LevelController = function (superThis) {}; LevelController.prototype = {}; PlayCon.prototype.makeSchoolFish(superThis){ superThis.makeFish(); } // … BasicGame.Game.prototype = { create: function () { this.game.levelController = new LevelController(this, playerType); this.game.levelController.makePlayer(playerType); // … }, makeFish: function(){ ///this is where i want to get too } // … }; Yes i got that far but i want to come back to game.... Link to comment Share on other sites More sharing options...
jjwallace Posted April 10, 2017 Author Share Posted April 10, 2017 Ohh i think i got it working. Link to comment Share on other sites More sharing options...
Recommended Posts