Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Adding multiple details to a list

Discussion in 'Scripting' started by Simpso, Mar 4, 2019.

  1. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    hi everyone,

    Was hoping to see if there was a slicker way to do this or if the way I'm proposing below is the way to do it.

    Basically I have a list of details I want to add to a list which I want to preload.
    My current thinking is I will need to enter all these details into a script, so for example

    List.add(variable1,variable2)
    Varaible1 = bill
    Variable2 = male

    Now would I just need to repeat the above process over and over to add all my details into a list?

    Or can I do some kind of loop to cycle through adding to my list?

    Hopefully this makes sense to someone :)
     
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,584
    Why you don't try simple for loop?
     
  3. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    That's where I'm getting a bit lost.
    If I had a loop where would I put all my variable details to feed into the loop?
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,584
    If all are the same then inside loop.
    If not the same, then you need add line by line to list anyway.
     
  5. Simpso

    Simpso

    Joined:
    Apr 20, 2015
    Posts:
    158
    Yeah they would all differ. Ok that's cool
    So pretty much what I said above.
    Thanks dude, just wanted to check I wasn't doing it a long way and round or something.

    Thanks again
     
  6. WheresMommy

    WheresMommy

    Joined:
    Oct 4, 2012
    Posts:
    890
    Depends what you want to do with your list and what the values are. You could make a var list but also a class list where the class has your information or their variants and then add them to the list.