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
1
Question by mmangual_83 · Jan 03, 2014 at 06:10 PM · c#list

My string list is empty

I have this list

     //TODO: Put these lists in a separate method 
     public static List<string> task1Gesture = new List<string>(new[]
     {
         "Tap",
         "Grab",
         "Grip"
     });


And this other list which will store the contents of the first list: public static List selection = new List();

When the user presses a button this happens:

 if (drawButon(btn_Next, "Next"))
 {
     if (Cube_DemoPhase.task1Gesture.Count > 0)
     {
         Cube_DemoPhase.selection.Add(Cube_DemoPhase.task1Gesture[Cube_DemoPhase.randomIndex_task1]);
         Cube_DemoPhase.task1Gesture.RemoveAt(Cube_DemoPhase.randomIndex_task1);
 
         if (Cube_DemoPhase.task1Gesture.Count == 0)
         {
             //TODO: Logic for next task goes here
             return;
         }
 
         Cube_DemoPhase.randomIndex_task1 = Random.Range(0, Cube_DemoPhase.task1Gesture.Count - 1);
     }
 }


Then I am outputting my list information into this string array here:

 string[] gestureOptions = {   Cube_DemoPhase.selection.ConvertToString(),
                                   Cube_DemoPhase.selection.ConvertToString(),
                                   Cube_DemoPhase.selection.ConvertToString()
                               }; 


Then I call this array into the OnGUI() method

But for some reason my list shows up empty. Can anyone help me figure out the reason behind this? Thank you very much!!!

Comment
Add comment · Show 11
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 Key_Less · Jan 03, 2014 at 06:33 PM 0
Share

I believe I tried helping you with a very similar question that you posted here yesterday.

avatar image mmangual_83 · Jan 03, 2014 at 06:40 PM 0
Share

@$$anonymous$$ey_Less you did indeed help me. But for some reason I am still getting an empty list. The thing is that I kept a debug log to see if it is adding anything when the user clicks on the button and it is indeed adding them. But when I cal that same list from another class the list seems to be empty.

avatar image RudyTheDev · Jan 05, 2014 at 08:29 PM 0
Share

We need more detail than that. Which list is empty exactly -- gestureOptions, Cube_DemoPhase.selection, task1Gesture? And how do you deter$$anonymous$$e it is "empty"? And what's the code from the other class that sees it as empty?

avatar image mmangual_83 · Jan 05, 2014 at 08:54 PM 0
Share

@$$anonymous$$TheDev I figured out why the list is empty and now it id not. I dug up this piece of code that may help me but what it is doing is printing random elements from my list non stop, but I want to print the order in which the random number generator had picked it during gameplay.

 for (int i = gestureOptions.Length - 1; i > 0; i--)
         {
             var r = Random.Range(0, i);
             var tmp = gestureOptions[i];
             gestureOptions[i] = gestureOptions[r];
             gestureOptions[r] = tmp;
             drawSelectionGrid(selGrid_GestureOptions, gestureOptions, ref gestureIndex_Block_Task1, 3);



You have any idea on how to get this to print how I want it? I know I am close to figuring this out with that code snippet, looks "hacky" I know and I will figure out a better solution than that but right now this is what I have to work on. Hope this diagram helps. And thank you, friend.

alt text

randomoutput.png (23.9 kB)
avatar image iwaldrop · Jan 05, 2014 at 09:19 PM 0
Share

It's never going to print out in the same order that you previously generated unless you use those values. I already gave you the solution in your other question's thread.

Show more comments

1 Reply

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

Answer by mmangual_83 · Jan 07, 2014 at 02:12 PM

I figured it out:

 //declare in my globals
 string[] gestureOptions_task1 = Cube_DemoPhase.task1Gesture.ToArray();
 //This goes into the update method
 var gestures = new string[gestureOptions_task1.Length];
 
         for (var i = 0; i < gestures.Length; i++)
         {
             gestures[i] = Cube_DemoPhase.index_task1[i];
         }


I also made sure that the second list where I was saving the data of the first list was also of the same variable type. So in my case I needed both lists to be strings.

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

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

Related Questions

A node in a childnode? 1 Answer

Multiple Cars not working 1 Answer

C# Displaying List Elements in Multiples 1 Answer

Printing a GUI selection grid in order 1 Answer

Printing an ordered 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