- Home /
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?
There's no reason to ever use Array, all it does is cause problems. Use List ins$$anonymous$$d.
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.
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 ins$$anonymous$$d of .length. Ins$$anonymous$$d of
var characterList : Array = new Array();
use
var characterList = new List.<character$$anonymous$$isc>();
(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 $$anonymous$$ac/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-consu$$anonymous$$g than switching to List. So switching to List could be easier overall and your code will be cleaner and faster.
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.
Your answer
Follow this Question
Related Questions
Error building Player: Win32Exception - with plugin? 1 Answer
Some problems after switch the game for iOS mode 2 Answers
Is not a Member of Collisions 2 Answers
Access to a variable inside a C# class 2 Answers
Button is not a member of GUI? 2 Answers