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 /
avatar image
0
Question by naqvir · Apr 05, 2012 at 02:04 AM · errorgameobjectloopdictionarycompiling

Compilor Error using Dictonary collection

Hi everyone,

Ive got some code here that utilises a dictionary construct. And in this dictionary construct i have specified a gameobject as the key type and a GENERIC list of type component as the value type. However i seem to be recieving some compile errors. I just want to make sure that i am using the types correctly... I am getting these sort of compile errors;

Insert "semi colon on line 1" (which i already have),and for line 8, i get 3 errors "expecting > found >>" ," expecting > found ("," expecting ( found )"..

Also is looping over a dictionary the same as looping through a hashtable?

Thanks alot in advance

The code i have is here.

     using System.Collections.Generic;
 
 
 var componentsExtracted:Dictionary;
 
 function Start () 
 {
     componentsExtracted = new Dictionary.<GameObject,List.<Component>>();
 }
 
 
 function findComponent(selectedObject:GameObject) 
 {
     if(Input.GetKeyUp(KeyCode.E)) {
     //RETRIEVES ALL COMPONENTS IN THE SELECTED OBJECT    
         var componentsFound:Component[] =  selectedObject.GetComponents(typeof(Component));
     //RETRIEVE A RANDOM COMPONENT
         var component:Component = findRandomComponent(componentsFound);
     //ADD COMPONENT TO WITH ORIGIN (GAMEOBJECT) REFERENCE TO DICTIONARY
         addToDictionary();                       
     }
     
 }
 
 private function findRandomComponent(componentsFound:Component[]) 
 {
 // INITIALISE COMPONENT CONTAINER
     var chosenComponent:Component;
     
     do 
     {
     // RETRIEVES A RANDOM NUMBER
         var ranNum:int = Random.Range(0,componentsFound.length);
     // RETRIEVES A CHOSEN COMPONENT
         chosentComponent = componentsFound[ranNum];
     }
     
 // WHILE COMPONENT IS NOT OF TRANSORM...PARTICLEEMITTER....(ADD MORE)
     while((typeof(chosenComponent)!= Transform) && (typeof(chosenComponent)!= ParticleEmitter));
     
 // RETURN RANDOM COMPONENT
     return chosenComponent;
 }
 
 private function addToDictionary() {
     
 
 }

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by naqvir · Apr 05, 2012 at 02:30 AM

honestly i cant believe this , but by adding a space to line 8 it removes 3 of the compilor errors.

Before

  componentsExtracted = new Dictionary.<GameObject,List.<Component>>();

Correct verision

  componentsExtracted = new Dictionary.<GameObject,List.<Component> >();

I have no idea why that worked, which is annoying...... :S

I am still getting the import decleration compile error though........... better start checking spaces :/ it expects a semi colon at the end, but i alrady have it :/

 using System.Collections.Generic;

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 Eric5h5 · Apr 05, 2012 at 02:38 AM 2
Share

"using" is not a JS keyword, it's C#. In JS you use "import". And yes, the JS compiler has difficulty with nested generic syntax, where it wrongly interprets >> as the bitshift operator. Otherwise, spacing doesn't make a difference.

avatar image naqvir · Apr 05, 2012 at 02:44 AM 0
Share

thanks alot Eric! :D

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Dictionary within a dictionary? 1 Answer

Why is my variable updating when it shouldn't? 1 Answer

Why don't my gameobjects load in when I export my game to webgl?,Why don't any of my objects render when I export my game to webgl? 0 Answers

Unity crashes on GameObject = hit.collider.gameObject; 1 Answer

typedefing in unity 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