x


Class error: BCE0019: 'xxxx' is not a member of 'Object'.

I'm using Javascript and Unity Pro 3.4.2.

Everything works fine, but when I use #pragma strict I get BCE0019 errors.

Here is where I define my variables:

var characterList : Array = new Array();
var theEditedCharacterName : String = "";
var theGender : String = "f";

class characterMisc{
    var name;
    var gender;
} 

Then, later in the code, I use this:

// add character to character object list...
characterList[charListCount] = characterMisc();
characterList[charListCount].name = theEditedCharacterName;
characterList[charListCount].gender = theGender;

And... I get the following errors:

Assets/Scripts/game_manager.js(2554,54): BCE0019: 'name' is not a member of 'Object'. 
Assets/Scripts/game_manager.js(2555,54): BCE0019: 'gender' is not a member of 'Object'. 

Again, I'm using Javascript. Can someone tell me in simple terms how to resolve this?

more ▼

asked Jan 23 '12 at 10:45 PM

Ony gravatar image

Ony
903 29 36 48

There's no reason to ever use Array, all it does is cause problems. Use List instead.

Jan 23 '12 at 11:31 PM Eric5h5

I've got arrays scattered all through my code and it's been working for about two years now in a released game. I'd rather not have to go through and rewrite reams of code just to change that if possible. What's wrong with arrays? They have always worked fine for me except now if I try to use pragma strict.

Jan 24 '12 at 01:57 AM Ony

It's generally pretty trivial to change Array to List. Access is the same, and most of the methods are the same (Add, Remove, Reverse, etc.). The main code difference in most cases is how they are declared, and using .Count instead of .length. Instead of

var characterList : Array = new Array();

use

var characterList = new List.<characterMisc>();

(You should have import System.Collections.Generic; at the top of the script.) The other code you posted should work the same, except it will be much faster and won't generate errors. And that's what's wrong with Array: it's quite slow, and it's not type safe. Lists also have quite a bit more functionality.

Considering that the majority of platforms that Unity supports require #pragma strict, and even for Mac/PC/web it's added to new scripts by default in Unity 3.5, it would be a good idea to stop using Array. While it's possible to make Array work with #pragma strict, it requires manually casting to the correct type when you access elements, and that still doesn't help with the speed. This means that if you don't switch the code to List, you're going to have to go through and manually cast everything, which will probably be more time-consuming than switching to List. So switching to List could be easier overall and your code will be cleaner and faster.

Jan 24 '12 at 02:46 AM Eric5h5

Ah, ok that makes sense then. I didn't realize it would be that relatively simple to switch over to lists, so I'll give it a shot tomorrow and see how it goes. Thanks for the info, Eric.

Jan 24 '12 at 09:31 AM Ony
(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1951
x337
x124
x111
x32

asked: Jan 23 '12 at 10:45 PM

Seen: 1216 times

Last Updated: Jan 24 '12 at 09:31 AM