How to call other script file functions?

I need in the UI.js calls a function in another script,
app._openDoor.toggle(); but be prompted to “app._openDoor.toggle is not function”.
I try to :‘enterCar:toggle’); and app._openDoor.on(‘enterCar:toggle’);
but can’t find the function toggle().

I use a lot of time to solve it without success.

1 Like

Hi yangcj, the ‘app’ object is part of the ‘this’ object in the component script. Without looking at your code, I guessing that you will just need to add ‘this’ at the beginning of those lines of code involving the fire and open event calls.


This is assuming that ‘openDoor’ object has been assigned to the ‘app’ object.

If you want to call a function from another script that is attached to an entity, you need to have a reference to the entity to get to the script instance. Eg.


var Door = pc.createScript('door'); = function() {
    // Do something in function


var Trigger = pc.createScript('trigger');
Trigger.attributes.add('doorA', {type: 'entity'});

Trigger.prototype.update = function() {
    if (/*something*/) {;

If you are still have problems with this, can you provide a link to your project please? It will help us solve your problem faster :slight_smile:


Thank you very much for your detailed answers. I’m trying to modify again.
If I are still have problems with this ,I request your help again.

Development consists loads of debugging - process of finding and investigating issues and information in your code.
Please refer to this page: that helps to get used to dev tools in your browser, that allows you to debug your code. This will help you to understand what is going on better.‘enterCar:toggle’);
This is assuming that ‘openDoor’ object has been assigned to the ‘app’ object.

Can you specify how we can attach a script to the “app” object?