Jump to content

Multiple Javascript Files and Variables Question.


jjwallace
 Share

Recommended Posts

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

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

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...