[SOLVED] Multiplayer tutorial: network.js: TypeError: this.app is undefined

Hello again,

This time i got an error with this.app

The code look like that, i have changed Player to player and Other to other_player to match my scene objects name :

Hi @qtestman,

What is the error exactly?

Sorry, it’s

[network.js?id=33676145&branchId=4cab773f-36df-4e5c-ae01-023107753be7:9]: TypeError: this.app is undefined

Most likely, you’re trying to use this.app in an anonymous function.

For that, you need to specify what this is with bind().

For example:

io.sockets.on('connection', function(socket) {
   // now you can use this.app, courtesy of bind(this)
   this.app.findByName('test');
}.bind(this));

It should be in network.js ?

That code needs to go inside the Network.prototype.initialize() method:

var Network = pc.createScript('network');

Network.prototype.initialize = function() {
    this.player = this.app.root.findByName('Player');
    // ...
    this.socket = io.connect('https://...');
};

Please, refer to the tutorial project and study the script example. You can find all the project scripts under the scripts folder in the project root.

Yes, thank i forgot the example project…

There is usefull exemple for Glitch server here :

1 Like