imLeyenda Posted November 24, 2015 Share Posted November 24, 2015 Hi guys, im making a multiplayer game, but now i have a dude. I have something like "https://github.com/p...Templates/Basic", and i want to access a "Game.js" function that i created, and when a i use " BasicGame.Game.myfunction()" the console says to me that is not a function... Greatings. Link to comment Share on other sites More sharing options...
Gob0 Posted November 25, 2015 Share Posted November 25, 2015 Hi, may be this example can help you? http://phaser.io/examples/v2/create/generate-sprite Link to comment Share on other sites More sharing options...
imLeyenda Posted November 25, 2015 Author Share Posted November 25, 2015 I havent explained well. I have something like "https://github.com/photonstorm/phaser/tree/master/resources/Project%20Templates/Basic", and i want to access a "Game.js" function that i created, and when a i use " BasicGame.Game.myfunction()" the console says to me that is not a function... Thanks Link to comment Share on other sites More sharing options...
forkgame Posted November 26, 2015 Share Posted November 26, 2015 can you show us your code?I can't understand your explanation. Link to comment Share on other sites More sharing options...
Gob0 Posted November 26, 2015 Share Posted November 26, 2015 try to use var oBGame = new BasicGame.Game(myGame); // replace myGame with instance of current phaser game Link to comment Share on other sites More sharing options...
imLeyenda Posted November 26, 2015 Author Share Posted November 26, 2015 Now works the call but game is not defined I have this:game = new Phaser.Game(config);game.state.add('Boot', warpgalaxy.Boot);game.state.add('Preloader', warpgalaxy.Preloader);game.state.add('Game', warpgalaxy.Game);Server.bind('message', function( data ) { data = JSON.parse(data); requestType = data['requestType']; if (requestType == "userLogged") { $('#window_login').toggle(); startWarpgalaxy(data['username'], data['x'], data['y'], data['frame']); wpgame = new warpgalaxy.Game(game); wpgame.myFunction(); }});Var game is global defined. Link to comment Share on other sites More sharing options...
Gob0 Posted November 26, 2015 Share Posted November 26, 2015 It's a normal thing as Server.bind declares a new function. When the code runs in this function, it can't access variables outside its scope So you can't read "game" variable in a local function, you have to access it by classname.game (where classname is the class containing variable alled "game") Link to comment Share on other sites More sharing options...
imLeyenda Posted November 26, 2015 Author Share Posted November 26, 2015 Server.bind('message', function( data ) { console.log(game);}And works... Link to comment Share on other sites More sharing options...
Gob0 Posted November 26, 2015 Share Posted November 26, 2015 So it's ok? Link to comment Share on other sites More sharing options...
imLeyenda Posted November 27, 2015 Author Share Posted November 27, 2015 No, in the function game doesnt exist, but is declared, i dont know what is going on... Link to comment Share on other sites More sharing options...
Gob0 Posted November 27, 2015 Share Posted November 27, 2015 Are you sure the error occurs using "game" variable? This code seems (to me) weird, why don't you use game.state.start('Game') instead? wpgame = new warpgalaxy.Game(game);wpgame.myFunction(); Link to comment Share on other sites More sharing options...
Recommended Posts