Hi,
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 : app._openDoor.fire(‘enterCar:toggle’); and app._openDoor.on(‘enterCar:toggle’);
but can’t find the function toggle().
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.
door.js
var Door = pc.createScript('door');
Door.prototype.open = function() {
// Do something in function
};
trigger.js
var Trigger = pc.createScript('trigger');
Trigger.attributes.add('doorA', {type: 'entity'});
Trigger.prototype.update = function() {
if (/*something*/) {
this.doorA.script.door.open();
}
};
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
Development consists loads of debugging - process of finding and investigating issues and information in your code.
Please refer to this page: http://developer.playcanvas.com/en/user-manual/scripting/debugging/ 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.