[SOLVED]how to call functions from another script

Hi,

I’m trying to figure out how to call a function from another script. Something that works like a .h file in c++.

Basically, I have a script(main.js) with a function called character_jump() ; then I have another script(myGUI.js) with a gui that needs to call that function. Is there a way to link separate js files together?

I’ve tried using GameObject.GetComponent but that it’s not working out for me.

Here’s a snippet:

var ref : main = gameObject.GetComponent(main);
...
function button()
{
 ref.character_jumping();
}

Thanks in advance.
-Hakimo

i haven’t tested it, but this is how i would probably do it

var ref : main;

function Start(){
 ref = gameObject.GetComponent(main);
}

...

function button()
{
 ref.character_jumping();
}

also, make sure character_jumping() is a public function, otherwise you’d have to use SendMessage() to call it

Thanks very much, that actually works. They have an example that I tried to follow but didn’t work out. Here’s a link Example. Not sure why they’d put it like this.

Thanks again :slight_smile: