need help with resource.Load (javascript)

Hi

I am new to this forum, so I hope this thread comes right :slight_smile:

I’m trying to load a resource (an image) stored in assets/Resources called “robot” using this code:

class Card extends System.Object
{
	var isFaceUp: boolean = false;
	var isMatched: boolean = false;
	var img: string;
	
	function Card()
	{
		img = "robot";
	}
}

function BuildGrid()
{
	GUILayout.BeginVertical();
	for(i = 0; i<rows; i++)
	{
		GUILayout.BeginHorizontal();
		for(j = 0; j<cols; j++)
		{
			var card:Object = aGrid[i][j];
			if(GUILayout.Button(Resources.Load(card.img), GUILayout.Width(cardW)))
			{
				Debug.Log(card.img);
			}
		}
		GUILayout.EndHorzontal();
	}
	GUILayout.EndVertical();
}

As you can see the constructor for card fills the img variable with the value “robot” but when I try to test my game I get an error message saying:

BCE0018: The name ‘string’ does not denote a valid type (‘not found’). Did you mean ‘Boo.Lang.Compiler.IO.StringInput’?

I don’t understand why I get this error. Anyone else knows?

For JavaScript, I think you want ‘String’ and not ‘string’:

http://wiki.unity3d.com/index.php/Head_First_into_Unity_with_UnityScript#It.27s_String_.28Mono.27s_String_class.29_and_not_string

please declare rows,cols some more variable first then try