Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by stargamingentertainment · Jun 24, 2017 at 11:41 PM · c#listproperties

check if a list contains the same id as in another list

Hi all

First of all i don't normal ask for help because the whole part of learning to code is to do it your self but this one has been bugging me for nearly a week.

For days now I've been trying to loop though all the available pets in the (petsInDatabase list), to check if the user has seen or captured any of the pets, by its petID. By searching through and comparing against the users (usersPetIndexInDatabase list) of all the users seen and captured pets.

If a pet id is matched in both lists, then a check is made to see if the pet with that id, was seen or caught and will instantiate the correct image game object, else if there isn't a match then instantiate a empty game object.

i finally found a way, using the idea from this link: [link text][1] [1]: http://answers.unity3d.com/questions/794811/check-if-list-contains-item-with-matching-string-p.html but every time i run unity and click the UI button, that calls the LoadPetIndexFromDatabase() method, it fezzes unity and I have to false quit the unity editor.

Below is the method that gets executed from the UI Button, this method works fine as this is from another c# script from my project.

The petsInDatabaseScriptList is just a list that will hold all the scripts attached to the instantiated pet game objects, within the (Pet Index List Manager script)

 public void LoadPetIndexFromDatabase()
     {
         if (petsInDatabaseScriptList.Count < petDatabaseSerializer.petDatabase.petsInDatabase.Count)
         {
             for (int i = 0; i < petDatabaseSerializer.petDatabase.petsInDatabase.Count; i++)
             {
                 SearchPetsAvailable(petDatabaseSerializer.petDatabase.petsInDatabase[i].PetID);
                 Debug.Log("pets in database increment id " + i);
             }
             Debug.Log("Successfully Added all the pets into the users pet index list");
 
         }else{
             Debug.Log("Already added all the pets into the users pet index list!!");
         }
     }

Below is the SearchPetsAvailable method that get executed from within the body of the above method LoadPetIndexFromDatabase(). The problem lies within the for loop in the below method, because when i comment the whole for loop out, the unity console logs the (pet id converted)

 public void SearchPetsAvaiable(string _petID)
     {
 
         int petID = Convert.ToInt32(_petID);
         //bool isInList = false;
         Debug.Log("pet id converted = " + petID);
 
         for(int i = 0; i < usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase.Count;)
         {
             Debug.Log("pets in pet index increasment id " + i);
 
             //if the pet ID From the avaiable pets, can be found in the users pet index, then check the status
             if (usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase[i].PetID == petID)
             {
                 if (usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase[i].PetStatus == "seen")
                 {
                     Debug.Log("seen " + i);
                     AddSeenPetToPetIndexList(usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase[i].PetIndexID, usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase[i].PetID);
           
                 }else if (usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase[i].PetStatus == "caught"){
                     Debug.Log("caught " + i);
                     AddCaughtPetToPetIndexList(usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase[i].PetIndexID, usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase[i].PetID);
                 }
             }else{
                 Debug.Log("un " + i);
                 AddUnknownPetToPetIndexList(petID);
             }
         }
     }

it would be great if someone could help me and any others that are trying to accomplish this, or point me in the right direction

thanks for any help

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
1
Best Answer

Answer by thePeine · Jun 25, 2017 at 09:50 PM

It looks like you're missing the i++ in the bottom loop. So your'e just looking at [0] over and over again infinitely.

Comment
Add comment · Show 1 · 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 stargamingentertainment · Jul 19, 2017 at 08:17 PM 0
Share

Thank you very much, your correct it was the i++, but i did fix it that night but then i forgot to come on here and say Ive fixed it. I missed it out because i normal copy and past for quickness. But for the above incorrect for loop i wrote it out quick, and like you pointed out it was the i++.

so thank you any way

cheers ricky

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

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

Related Questions

Removing items from list by OnTriggerExit 2 Answers

C# list type not working 2 Answers

LoadScene not working 1 Answer

Tracking Long Lists and Scalability 0 Answers

List instance is always the same as the blueprint ? 0 Answers


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