Regarding Array and the new stricter compile in 3.4

Maybe it was bad practice? But it was convenient. I have a lot of this going on: I have a structure (class) I define. Then I make an Array of them, eg.:

class data
{
  var count : int;
  var name : string;
}

var listOfData = new Array()

....
   listOfData[0] = new data();
or
   var d = new data();
   listOfData.Push (d);
....
   listOfData*.name = "Joe"; // for example*


This worked fine, so I used it a lot. Now with the new strictness, I get errors on all such accesses, because it doesn’t know what type the elements of that array are, right?
So what’s the best way to fix this? Is there a way to declare or initialize the array variable? Or do I have to either create a new temp var of my type, assign, and use that? Or use '(listOfData as data).name’ everywhere?
(note this is a simplistic example, my actual code is much more involved and would be a bear to change, and global search/replace would be just as tedious, so I’m hoping for a declarative fix)

The “new strictness” only applies to iOS/Android, not Mac/PC standalone/web, and it’s not really new, it just applies to script compilation now instead of waiting to hit you with errors when you try to make a build. (And this is in fact what the old Unity iPhone used to do when it was a separate app, so it’s definitely not new.)

Anyway, yes, it’s kind of bad practice to use the JS Array class; use generic Lists instead. Better/faster/easier (you don’t have to manually cast stuff to work with #pragma strict). You’re going to have to do a lot of manual casting anyway if you stick with Array, so it would be a good idea to take the opportunity to switch to Lists.

Unfortunately I believe a thorough search and replace is needed. That’s dynamic typing so you really should stay away from it anyway, and I can’t think of any hacks that would do what you want. I would suggest switching to a Generic list if you are going to have to rewrite all your arrays. It’s type safe.

Now that I think of it, you could do something like this for a universal search and replace.

I think the only problem you are having is that you have to declare the type of the variables, so in your case simply have :

var listOfData : Array = new Array();

var d : data = new data();

I’m still doing this in unity 3.4