bymafmaf Posted November 16, 2015 Share Posted November 16, 2015 I have this function in my Kare.StartMenu.prototypeenterLobby: function (pointer) { Kare.socket = io.connect(Kare.serverUrl); Kare.socket.emit('sendDeviceID', Kare.deviceID); Kare.socket.emit('matchUsers'); Kare.socket.on('usersMatched', function(){ this.state.startGame(); }); }Normally, states have "state" property as StateManager so that we can call it as this.state. However, here I use socket.io and in Kare.socket.on() function, "this" becomes socket object so this.state is undefined. I tried several tricks but they didn't help. How can I start my game? Link to comment Share on other sites More sharing options...
jmp909 Posted November 16, 2015 Share Posted November 16, 2015 Try .bind(this) on the end of your on function maybeOr you could var that=this and use that inside your callback Link to comment Share on other sites More sharing options...
bymafmaf Posted November 16, 2015 Author Share Posted November 16, 2015 I figured it out but I'm sure there is a better way. pointer here is the image that I added click signal and it has game property. So pointer.game.state.start worked. But there must be a way to access it in every scope I guess. Link to comment Share on other sites More sharing options...
Recommended Posts