problems accesing C# variable in javascript

I’d like to acces the variable “score” in “caughtSomething.cs” in “playerControls.js”

Unity gives the following error: "The name ‘caughtSomething’ does not denote a valid type (‘not found’). "

Note: I’m new to unity and not experienced with scripting. (just a highschool student trying to create a mobile app for a schoolproject :))

EDIT: Note that both scripts are attached to the object “Aapje” and are in the subfolder Scripts in the assets window.

I have the following in “playercontrols.js” :

#pragma strict

var moveLeft 		: KeyCode ;
var moveRight 	: KeyCode ;

var speed : float = 2 ;
var caughtSomethingInstance : caughtSomething ;
var score;

function OnGUI () {
    GUI.Label (Rect (10, 10, 100, 20), "Score = "+score);
}

function Update () 
{	
	caughtSomethingInstance = GameObject.Find("Aapje").GetComponent(caughtSomething);
	score = caughtSomethingInstance.score;
	if 		(Input.GetKey(moveLeft))
	 {
	 	rigidbody2D.velocity.x = 2;
	 }
	else if (Input.GetKey(moveRight))
	 {
	 	rigidbody2D.velocity.x = -2;
	 }
	else
	{
		rigidbody2D.velocity.x = 0;
	}
	
}

I already wrote the answer to a similar question. CSharp and JS can’t see each other at compile time (different compilers are used for each language), but already compiled scripts can be seen by any language. If you place the C# script in Plugins or StandardAssets, and the JS script in another Assets folder (Assets/Scripts, for example), the C# script will be compiled in the “first wave”, thus the JS script will know it and compile ok. And in code:

 var csharpcomponent:CSharpComp;
 function Start(){
  csharpcomponent = this.gameObject.GetComponent(CSharpComp);
 }

But this is bad practice to have a project with both JS and C#. You should consider translating all scripts to one unique language. I hope that it will help you.

You need to put the c# into a special folder so that the type is available to the javascript script.

Special Folders and Script Compilation Order specifically calls this out:

A common example is where a UnityScript file needs to reference a class defined in a C# file. You can achieve this by placing the C# file inside a Plugins folder and the UnityScript file in a non-special folder. If you don’t do this, you will get an error saying the C# class cannot be found.