x


why this does not work (Lists)

if i put these lines of code in the script:

import System.Collections.Generic;
var boxColliderList : List.<Collider>=new List.<Collider>();

i get this error:

Unexpected Token: ..

i wanted to start using lists instead of arrays but no luck... it seems that most simplest thing is not working, like declaring a list...i am using unityscript as you can see....

thanks!

cross post in unity forums: http://forum.unity3d.com/threads/80203-can-someone-explain-to-me-why-this-does-not-work

more ▼

asked Mar 02 '11 at 11:35 AM

pretender gravatar image

pretender
497 121 134 145

In what line / column do you get this error? import should be used at the top of your script. Don't use it inside a function or class.

Mar 02 '11 at 12:46 PM Bunny83

The List<> works even without the import (at least for me...)

Mar 02 '11 at 12:48 PM Bunny83

-1 for posting on the forum too, and not cross-linking. http://forum.unity3d.com/threads/80203

Mar 02 '11 at 12:51 PM Jessy

I have a little test script with exactly the same code and it works without any errors. Maybe there's something wrong after this two lines? Or even before? Another general programming hint: if you call your variable boxColliderList it should contain BoxColliders. If you want to store different colliders, the variable should be called just colliderList. The variable name should represent it's usage

Mar 02 '11 at 01:13 PM Bunny83

yes it is meant to hold boxColliders...i changed the name of the variable and it did not make any change. still getting the error. also i tried what jessy proposed, that did not work... i do not know what is going on. this part of code is at the top of the script.

Mar 02 '11 at 01:15 PM pretender
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first

You need Unity 3 to be able to use generics in js/unityscript

2.6 will just throw errors at you

more ▼

answered Mar 02 '11 at 02:22 PM

Mike 3 gravatar image

Mike 3
30.5k 10 65 252

ohhh...i was not aware of this :(

Mar 02 '11 at 02:38 PM pretender

but wait, i am using unityscript

Mar 02 '11 at 02:41 PM pretender

uh, typo - fixing (it should be js, not c# - 2.6 has generics for c#just fine)

Mar 02 '11 at 02:45 PM Mike 3

damn...so i am stuck with arrays??

Mar 02 '11 at 02:58 PM pretender

You could use ArrayList (which acts like List), but that's about it unfortunately

Mar 02 '11 at 03:03 PM Mike 3
(comments are locked)
10|3000 characters needed characters left

">= " is interpreted as greater than or equal to. Use nicer spacing; pixels are plentiful on modern monitors. ;-)

var boxColliderList : List.<Collider> = new List.<Collider>();

Also, it's JS, so you don't need new if you don't want, and you don't need to declare the type, either.

var boxColliderList = List.<Collider>();
more ▼

answered Mar 02 '11 at 12:43 PM

Jessy gravatar image

Jessy
15.6k 72 95 196

i tried this and it did not work. both thing you suggested, still getting the "Unexpected Token : .."

the line error appear is this var boxColliderList : List. = new List.();

it is strange to be honest... also sorry about cross linking..

Mar 02 '11 at 12:58 PM pretender

Didn't work for me; the space is required on my system.

Mar 02 '11 at 01:36 PM Jessy

The space is a problem for me, but It's not the same problem the OP has. Also, I wouldn't go around advising people not to type their variable declarations unless it's really necessary.

Mar 02 '11 at 02:27 PM burnumd

burnumd, that's not dynamic typing. You can use the exact same code in C#, even, with only the dot left out. http://stackoverflow.com/questions/41479

Mar 02 '11 at 02:43 PM Jessy

Just removed my useless comments since it turned out that Jessy's answer is 100% right.

Mar 02 '11 at 03:11 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

You have a '.' between List and < ie List.< should be List<

more ▼

answered Mar 02 '11 at 01:47 PM

SpookyCat gravatar image

SpookyCat
436 5 5 12

ok ignore that, using UnityScript I see

Mar 02 '11 at 01:48 PM SpookyCat
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x1941
x38
x27

asked: Mar 02 '11 at 11:35 AM

Seen: 1600 times

Last Updated: Mar 02 '11 at 01:16 PM