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 Theopt · Dec 30, 2013 at 02:12 PM · javascriptobjectactivate

Run through hastable of objects

Well I'm running through a hastable of objects in order to set them as active (they are unactive as default).

for (var item : DictionaryEntry in player1hand){ var temp : Transform = player1hand[item.Key]; temp.active =true; }

being player1hand the hastable. I have two keys but only activates one object, why Is that?

Comment
Add comment · Show 6
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 Bunny83 · Dec 30, 2013 at 03:17 PM 0
Share

I have no idea what's your problem!?! So to sum up:

  • You have two items in the hashtable

  • Each with a unique key

  • You want to iterate through all items in the table

  • and activate the corresponding object

The way you do it, it should work. The only problem i can see is that you used the same key so there's only one item in the hashtable

avatar image Theopt · Dec 30, 2013 at 03:24 PM 0
Share

there are two items in the hashtable. and the key is being iterated right? edit: and the items have diferent keys because I've tried manually already.

avatar image Bunny83 · Dec 30, 2013 at 03:31 PM 0
Share

Are you sure that there are two items in the table? DictionaryEntry has both, the $$anonymous$$ey and the Value of each item.

Have you tried adding a Debug.Log inside the loop and let it print the key name. You should get two logs in the console if there are two items in the table.

edit
Example:

 for (var item : DictionaryEntry in player1hand)
 {
     var temp : Transform = item.Value;
     if (temp != null)
     {
         Debug.Log("$$anonymous$$ey: " + item.$$anonymous$$ey + " references a gameobject with the name: " + temp.gameObject.name);
     }
     else
     {
         Debug.Log("$$anonymous$$ey: " + item.$$anonymous$$ey + " is null!!!!!");
     }
 }
avatar image Theopt · Dec 30, 2013 at 03:51 PM 0
Share

hmm. the key isnt the same, but for some reason the item is. the problem was in the filling :x for some reason this wasnt working:

var aux2 = Random.Range( 0, player1deck.Count ); player1hand.Add(player1hand.Count, player1deck[aux2]); aux2 = Random.Range( 0, player1deck.Count ); player1hand.Add(player1hand.Count, player1deck[aux2]);

I was trying to get a random card but isnt working. the aux2 always saves the same

avatar image Bunny83 · Dec 30, 2013 at 04:46 PM 0
Share

Uhm, may i ask why you use a Hashtable? It seems you try to use it like an array or a List...

What is "player1deck"? is it a List or also a Hashtable? Where is player1deck filled and are you sure it's filled correctly?

Show more comments

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Dec 31, 2013 at 12:39 AM

I have a feeling that you actually don't need a Hashtable / Dictionary. An ordinary List will do.

You need to import the System.Collections.Generic namespace at the top of your script in order to use the generic List.

 // UnityScript
 var player1deck = new List.<Transform>();

A List allows adding and removing of elements but behaves like an ordinary array.

 player1deck.Add(T1);
 player1deck.Add(T2);
 player1deck.Add(T3);
 print(player1deck.Count);     // prints "3"
 
 print(player1deck[0].name);   // T1
 print(player1deck[1].name);   // T2
 print(player1deck[2].name);   // T3
 
 player1deck.Remove(T2);
 
 print(player1deck[0].name);   // T1
 print(player1deck[1].name);   // T3
 print(player1deck[2].name);   // ERROR since there are only 2 elements in the list
 
 player1deck.RemoveAt(0);      // removes the first(index 0) element
 print(player1deck.Count);     // prints "1"
Comment
Add comment · 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

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

19 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Move object to raycast point. 3 Answers

How To Deactivate A Parent (And Its Children)? 4 Answers

How to deactivate gameObjects instead of destroying them ? 1 Answer

Collision at which side? 1 Answer

Random instantiation at an object 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