Requiring Another Script

Greetings,

I have a script that has a function which I want to use in multiple other scripts. I’ve tried using the resource.load("/main/myresource") and require("/main/myresource") but neither have worked and I’m beginning to think I misunderstand what they are mean’t for. Require is for files outside the program right? And resource.load is for non-script files, like sprites? What can I do to call another script so I can apply it’s functions to another script. I know I could just copy and paste, but I’d like to be neat and tidy.

As an example:

Lets say I have two separate scripts. One with a function to kill an enemy, and the other controlling the enemy. enemyKill.script and enemyCon.script. INSIDE enemyCon.script is a function which checks if the health has gone below 1, and if so it calls the kill() function from within enemyKill.script.

Use a module for the common function - http://www.defold.com/manuals/modules/

1 Like