- Home /
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
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.
The List works even without the import (at least for me...)
for posting on the forum too, and not cross-linking. http://forum.unity3d.com/threads/80203
I have a little test script with exactly the same code and it works without any errors. $$anonymous$$aybe there's something wrong after this two lines? Or even before? Another general program$$anonymous$$g 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
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.
Answer by Jessy · Mar 02, 2011 at 12:43 PM
">= " 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>();
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..
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.
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
Just removed my useless comments since it turned out that Jessy's answer is 100% right.
Answer by Mike 3 · Mar 02, 2011 at 02:22 PM
You need Unity 3 to be able to use generics in js/unityscript
2.6 will just throw errors at you
uh, typo - fixing (it should be js, not c# - 2.6 has generics for c#just fine)
You could use ArrayList (which acts like List), but that's about it unfortunately
Answer by SpookyCat · Mar 02, 2011 at 01:47 PM
You have a '.' between List and < ie List.< should be List<
Your answer
Follow this Question
Related Questions
Scripting error! 1 Answer
How to enable a ParticleEmitter in scripting 2 Answers
Unknown Identifier 'List' 1 Answer
Errors in Vector2 variables 1 Answer
IComparable error due to float 1 Answer