LogicaLinsanity Posted January 24, 2016 Share Posted January 24, 2016 After the state has already loaded, i have a javascript method that gets called from my server in a client-server setup (SignalR hub). It looks something like this: connection.client.updatePlayerPosClient = (playerPosModel) => { Module.RemotePlayerManager.prototype.UpdateRemotePlayer(playerPosModel); } this calls a method in my exported class RemotePlayerManager. The breakpoint hits correctly at the UpdateRemotePlayer method. And her'es what the UpdateRemotePlayer method looks like: public UpdateRemotePlayer(playerPosModel) { this._zone.UpdateSpritePos(playerPosModel.Id, playerPosModel.X, playerPosModel.Y); } _zone is a variable that is assigned to in the constructor of RemotePlayerManager (I pass the "zone" state to this manager's constructor). If I set a breakpoint at the constructor level i do see the zone state is passed to the _zone variable. However, if I set a breakpoint at the code above when looking for "this._zone". _zone is undefined. the "this" scope correctly shows some other public property members of the RemotePlayerManager as well as the above public UpdateRemotePlayer class. but, somehow _zone is undefined? Edit: I may have narrowed things down to the fact that I'm trying to call a method from the state passed in the constructor of the typescript class, but the reference to that state is no longer there now that I've left the constructor? I don't know how to "hold" a reference to the state from an external plain old javascript method. Update (figured it out): Turns out MIXING javascript IIFE calls with typescript calls can be hazardous. I have a totally unrelated (i thought) hub start happening BEFORE this client method was bound. I realized, even tho, I have two Hubs, there's really only one hub.start(); silly me. Link to comment Share on other sites More sharing options...
Nonostante Games Posted January 24, 2016 Share Posted January 24, 2016 in js you shold create the TS "class". So write: new RemotePlayerManager().UpdateRemotePlayer(playerPosModel) of course the manager can be shared, so you have to create it before elsewhere and then call its method. Link to comment Share on other sites More sharing options...
drhayes Posted January 25, 2016 Share Posted January 25, 2016 You had "Module.RemotePlayerManager.prototype.UpdateRemotePlayer(playerPosModel);" in your code. That's the prototypal object, not the instance of the JS class. If your RemotePlayerManager is a singleton then you should probably use an object literal instead of a class. Link to comment Share on other sites More sharing options...
LogicaLinsanity Posted January 25, 2016 Author Share Posted January 25, 2016 1 hour ago, drhayes said: You had "Module.RemotePlayerManager.prototype.UpdateRemotePlayer(playerPosModel);" in your code. That's the prototypal object, not the instance of the JS class. If your RemotePlayerManager is a singleton then you should probably use an object literal instead of a class. Thanks, I realize I was making this mistake as well. I think that was the reason I was getting the original error I saw, because the prototype is not an instance. I'm not too familiar with vanilla js. Link to comment Share on other sites More sharing options...
Recommended Posts