Getting scripts to check each other in .js?

I can’t for the life of me get the GetComponent function to work. All I need is for 1 script to check a variable in a different script. How does one do that?

If you need to access a var in another script repeatedly, best practice is to cache a reference to it. The following code assumes your otherScript is called OtherScript(in JS), and is attached to an object named OtherObject.

var otherScript : OtherScript;
var otherObject : GameObject;

function Awake()
    otherObject = gameObject.Find("OtherObject");
    otherScript = otherObject.GetComponent(OtherScript) as OtherScript;
    otherScript.otherVar = whatever;


Of course, it might be simpler to just drag and drop in the editor if your situation allows it!

var otherScript : OtherScript // in the editor, simply drag and drop to this field the object your script is attached to.