U3 accessing class members

I have this code:

private var folders = new Array();

class Folder {
	var ID : int;
	var name : String;
	var address : String;
	var subfolders : Array;
	var files : Texture2D[];
	var fileCounter : int;
	
	function Folder() {
		ID = 0;
		name = null;
		address = null;
		subfolders = new Array();
		files = new Texture2D[1000];
		fileCounter = 0;
	}
}

function ScanResources () {
	// here i populate the array
	// [...]
}

function Start () {
	print (folders[0].name);  // <- here i get the error
}

the Print() gives me the error “name is not a member of ‘Object’”.
This worked fine in unity 2.6…
Any idea?

I’m guessing they’re still working on making UnityScript dynamic. Try:

print (Folder(folders[0]).name);

Perhaps you should submit a bug report on this.

it would be (folders[0] as Folder).name

and I think the changes and new power in UnityScripting in U3 came at the price of having to do basic typesafe coding yourself (type casting). It now seems to run on #pragma strict all the time (saves you lot of headache when moving with the code anywhere else than desktop and web, as all other platforms are permanentely in #pragma strict mode)

it works, thank you! :smile:

Ahh, I didn’t know UnityScript casting supported “as”. Does the whole TYPE(object) casting not exist in UnityScript?

No, you need to use the “as” operator or else just assign the value to a variable explicitly declared as the type you want:-

var f: Folder = folders[0];
var name = f.name;

no, no idea where that comes from aside of basic languages.

the standard casting in c style languages normally would be (Type)object, but UnityScript only supports the alternative object as Type casting.