before the new scripting system was out, we used to call functions on scripts on other entities like this:
var someEntity = app.root.findByName("SomeEntity"); someEntity.script.myScriptName.myFunctionName(someParameter);
but it seems that that is not how it works anymore since the console doesn’t show the functions defined in the scripts if we print out ‘someEntity.script.myScript’, it shows all variables defined like this:
this.myVariable = someValue;
but it doesn’t show the functions defined on the prototype like:
we know about the event listeners, but they are not always convenient since you have to set up a listener and an event which can blow up your code. Too many event listeners can also have negative impact on the performance of your applications,
Therefore we are looking for the more direct way to call functions on another entity, but thanks for your reply.
Actually, I am a novice in PlayCanvas. And I also met this problem a few days ago. I have no idea about that. So I just used the event listeners. Thanks for your remind about the event listeners’ nagative impacts. I am looking forward to the answer, too.
the problem might be another in the case that we’re using it then,
I tried in a blank project and it works just as you said, but in our use case I’m still getting an error:
ent.script[pScript][pFunction].apply(undefined, this.targetParametersArray[functionIndex]); ent is a variable filled with a target entity, pScript is a string equal to the name of a script on that entity, pFunction is a string which equals a function in the script and finally this.targetParametersArray[functionIndex] is a random string.
The error I see in the console sais: Uncaught TypeError: CreateListFromArrayLike called on non-object and references the line of code I mentioned above.
Are we missing some conversion or something like that, or do we have to address the functions of the script differently? I can print all of the variables into the console so they seem to be working.
Sorry for the ruckus - we just found the problem, which simply was that we gave apply a value out of the array instead of the whole array