SirSandmann Posted May 5, 2015 Share Posted May 5, 2015 Hey Guys,I have a problem with a function call with Phaser. I am a Javascript Noob and don´t know what I do wrong.Here is the critical Part of my Code, the whole Code is in one Scene.BasicGame.Multiplayer.prototype = {create: function(){ this.socket = io.connect('localhost:3010'); this.socket.on('startGame', function () { console.log('ShouldStartGame'); this.createActualGame(); });...},createActualGame: function(){// Define constants...}}My problem is that the function this.createActualGame is not called with the error: "TypeError: this.createActualGame is not a function".But the console log works fine. Thanks for your help!With kind regards,SirSandmann Link to comment Share on other sites More sharing options...
drhayes Posted May 5, 2015 Share Posted May 5, 2015 What's the value of "this" within your socket callback? Link to comment Share on other sites More sharing options...
SirSandmann Posted May 5, 2015 Author Share Posted May 5, 2015 I forgot to delete it. I edited the code. But the problem is still there. Link to comment Share on other sites More sharing options...
SirSandmann Posted May 5, 2015 Author Share Posted May 5, 2015 The Solution of the Problem is:socket = io.connect('localhost:3010');socket.on('startGame', function () {console.log('ShouldStartGame');this.createActualGame();}.bind(this));Topic can be closed! Link to comment Share on other sites More sharing options...
Recommended Posts