Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jan 17, 2015 at 11:48 PM by KazeEnji for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by KazeEnji · Feb 13, 2013 at 12:04 AM · javascriptlistsyntax

Problem declaring List variable in JS

Quick question, I see a lot of people on the forums using lists in Javascript. Everytime I try to declare one to use, I get an error on my console saying that "List" is an unknown identifier. Any ideas why this is?

Example declaration:

 var targetList=new List();

I've tried various other syntax from the forums and none of them work.

Thanks, -Kaze-

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

  • Sort: 
avatar image
1
Best Answer

Answer by AlucardJay · Feb 13, 2013 at 12:16 AM

You have to use this to use List :

 import System.Collections.Generic;

this is how to typecast a list of gameObjects :

 var inRangeList : List. < GameObject > ;

this is how to declare a list of gameObjects :

 inRangeList = new List. < GameObject > ();

Here is a really useful page on arrays and lists (for lists, scroll down to Generic List) : http://wiki.unity3d.com/index.php?title=Which_Kind_Of_Array_Or_Collection_Should_I_Use?

Comment
Add comment · Show 6 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KazeEnji · Feb 13, 2013 at 12:24 AM 0
Share

Thanks for the answer $$anonymous$$, however, I tried importing your first line of code already and I got an error, something like "you must declare the individual generic collections to import." or something like that.

avatar image AlucardJay · Feb 13, 2013 at 12:50 AM 0
Share

That is most strange. The link I provided shows how to manage all types of lists/arrays/etc, and this is directly from one of my working projects. What version of Unity and OS are you using?

avatar image KazeEnji · Feb 13, 2013 at 12:54 AM 0
Share

The issue was occurring in Win 7 w/ Unity 3.x and 4. I just recently upgraded to Windows 8 and still have Unity 4. The problem still persists.

avatar image KazeEnji · Feb 13, 2013 at 12:04 PM 0
Share

Hey, this ended up working! I must've mistyped something before because I'm not getting the error anymore. Will the import need to be done for every script I want to use lists in? Or if the system imports it on one script, can it be used for others?

avatar image AlucardJay · Feb 13, 2013 at 01:20 PM 0
Share

I wasn't sure as I've been adding it to every script with List, but after a quick test it seems you only need import System.Collections.Generic; on one of the scripts in the scene. (test was 2 scripts on the camera in a new scene).

Show more comments
avatar image
1

Answer by T27M · Feb 13, 2013 at 12:17 AM

I also get an error in unityscript try this

 var mylist = new System.Collections.Generic.List.&#60;GameObject>();
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KazeEnji · Feb 13, 2013 at 12:24 AM 0
Share

Thanks for the answer, I'll check this out when I get home.

avatar image T27M · Feb 13, 2013 at 08:44 AM 0
Share

Updated to the full code if your still having troubles. The list type goes between

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

List of objects with limited number availiable? 1 Answer

JS to C# List type problem 1 Answer

How do I use current List Object [i] as the string name? 3 Answers

Far Clipping Range syntax 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges