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 SubBassman · Aug 26, 2013 at 02:29 PM · liststring

Is it possible to name a list by a string variable?

So here's a function that's supposed to produce a quest ID. Currently I'm just adding a fixed name, indexed. (temporary) The real function is remmed. At the middle, there's a list declaration, but I'd like to create a new list for each quest based on the incoming ID. Is this possible at all? The other question is: is this a good approach?

 {
 
     string questID = "QuestID_";
     if (temporary == 1)
     {
     questID = questID+index.ToString();
     }
     else
     {
     //questID = AcquireInfoFromXML();
     }
     
     // Creating a list for a particular quest
     
     **List<string> questID_Entries = new List<string>();**
 
     
         
             for(int j = 0; j <= entry_Max; j++)
             {
         
             string entry = GetQuestEntries(j);
         
             if (entry!="")
                 {
                 questID_Entries.Add(entry);
                 Debug.Log(questID+questID_Entries[j]);
                 }
             }
       
     ///////////////////////////////////////////////////////////////

     return questID;
 }
Comment
Add comment · Show 3
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 perchik · Aug 26, 2013 at 02:30 PM 0
Share

Can you clarify what you mean about "Na$$anonymous$$g a list by a string variable"

The line you have starred creates a list of strings.

avatar image SubBassman · Aug 26, 2013 at 02:56 PM 0
Share

The name of the new list would be the string's value. So, the string Quest1 would create a list with the name Quest1 for its entries.

avatar image SubBassman · Aug 26, 2013 at 03:03 PM 0
Share

In other words, as I'm getting a particular questID, at the same time I'd like to create a list by the same ID.

2 Replies

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

Answer by roojerry · Aug 26, 2013 at 02:33 PM

You probably want to look at a Dictionary. You could use the string questID as the key and have a corresponding List for the value.

Comment
Add comment · Show 3 · 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 SubBassman · Aug 26, 2013 at 03:01 PM 0
Share

There's no corresponding list, because it's not yet created. This is the problem. :) I want to create the list first by the ID.

avatar image fafase · Aug 26, 2013 at 03:15 PM 0
Share

Store the ID's in a list/ array then once you want to add in the dictionary, do it.

 List<string> idList  new List<string>();
 static int index;
 idList.Add("Id1");
 idList.Add("Id2");
 
 var myDict = new Dictionary<string, List<GameObject>>();
 
 // Once you got the list to go with:
 myDict.Add(idList[index++], new List<GameObject>());

The static variable ensures to have only once the list id used.

avatar image SubBassman · Aug 26, 2013 at 03:27 PM 0
Share

Thank you.

avatar image
0

Answer by perchik · Aug 26, 2013 at 03:13 PM

Here's how you could actually use Dictionary to do what you want.

 Dictionary<string, List<string>> quests = new Dictionary<string, List<string>>(); 
 quests.Add["Quest1"] = new List<string>();
 quests["Quest1"].Add("whatever I'm adding to the quest list");



  


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 SubBassman · Aug 26, 2013 at 03:27 PM 0
Share

Thanks a lot.

avatar image SubBassman · Aug 26, 2013 at 03:31 PM 0
Share

Thank you guys for the answers.

avatar image perchik · Aug 26, 2013 at 03:48 PM 0
Share

If the answer is correct, please mark it as the right answer.

avatar image SubBassman · Aug 26, 2013 at 05:34 PM 0
Share

Sorry, I don't have time to dabble with this at the moment, but thanks again.

avatar image roojerry · Aug 26, 2013 at 05:55 PM 0
Share

haha, you are too busy to select a correct answer to the question, but you came back to respond. This question has been answered, please choose the answer that helped you and close this question for future reference.

And please watch the video on how this site works before posting again.

Show more comments

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

17 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

Related Questions

A node in a childnode? 1 Answer

Update List<> in editor 0 Answers

How do I make a list of lists? 2 Answers

Cannot convert string to int. 1 Answer

add items to a list 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