- Home /
Can't get list to work (simple)
Hey out there. I am trying to learn how to use lists in js.
I have
var thing1 = new List.<GameObject>();
var thing2 = new List.<GameObject>();
but I get this error message
ssets/My scripts/tryout.js(119,17): BCE0005: Unknown identifier: 'List'.
what's wrong? I'm not finding any clear instructions anywhere that explain for js
Answer by robertbu · Jun 29, 2013 at 02:41 PM
You need the following at the top of the file:
import System.Collections.Generic;
I tried that, but it throws millions of errors mainly on 'components of' parts of the script
The import is necessary. Did you include the ';' at the end? The following compiles and runs:
#pragma strict
import System.Collections.Generic;
var thing1 = new List.<GameObject>();
var thing2 = new List.<GameObject>();
function Start() {
for (var i = 0; i < 10; i++)
thing1.Add(new GameObject());
}
I put that in a new script and it does work. I wonder why it threw so many errors on my initial script?
this times * 100
BCE0019: 'blank' is not a member of 'blank'.
it also did
BCE0005: $$anonymous$$ identifier: 'blank'.
Don't know. If you want to post the entire script that generated the error, I'll take a look.
You'd be reading for 3 days. I think it had to with 'pragma strict' being added. It doesn't like getcomponent me thinks. I'm going to have to find alternative methods. I only wanted to dive into lists so I could serialize arrays.