Hello
How can I transfer data from one script to another script?
Hi @sevval_alatas,
Welcome. You can access the prototype of any instance of a script through the entity it’s attached to. You can do this by creating a script attribute:
https://developer.playcanvas.com/en/user-manual/scripting/script-attributes/
or adding it somewhere in the script (usually the initialize() function) with something as simple as
this.someVar = [anyValue]
Then you can access the script with something like:
someEntity.script.scriptName.someVar
The scriptName is the string value set at the top of all of your scripts: var VidHotSpot = pc.createScript('vidHotSpot');
Using that as an example, the scriptName would be ‘vidHotSpot’
Using events is also a handy way to communicate data between scripts that you don’t want to search through an entity for. Check out this documentation for that:
https://developer.playcanvas.com/en/user-manual/scripting/communication/