Call a function out of other script

Hello there! i am new to coding with javascript and playcanvas so i will link my project here:
https://playcanvas.com/project/866039/overview/testing

what do i want to achieve: well i want to call the dodamage function from the enemie and then it wil do damage and then the gamemanger wil update the health

anny one knows how to? or anny beter way?

ty for ready!

Hi @Timme_Kingma,

There are two main ways to communicate between two script instances:

  • Events
  • Getting a reference to the script instance directly

Check this manual page, it outlines both methods:

https://developer.playcanvas.com/en/user-manual/scripting/communication/

If you need additional help, feel free to ask.

1 Like

hey @Leonidas ive tried understanding the way how events work but still not yet understand

could you maybe make an example from 2 scripts 1 calling the other in the start and the other that has a function with an console.log print with hello world

if not i understand

if reading this thank you for reading and for the help