[SOLVED] Run function from another script

I know there is probably an super easy way to do this but i cant find it. I want to initialize my players with the funciton Network.logininit() but it says it doesnot exist. Im calling this from another script login btw.
https://playcanvas.com/editor/code/976292?tabs=100907833,100095452

actually i figured it out. attached a fire event to the root and fired it when the player logs in.

this.app.root.on('logininit'function(){
    //code here
}.bind(this));

fired it with

this.app.root.fire('logininit');
3 Likes

You got it!

You can study more on how scripts can communicate here: Communication | Learn PlayCanvas

3 Likes

You can also access the script type directly if you want to. There’s an example in the Orbit camera where the input scripts access the orbit camera script.

https://developer.playcanvas.com/en/tutorials/orbit-camera/

this.orbitCamera = this.entity.script.orbitCamera;
3 Likes