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]: check if list contains item with matching string property - Questions & Answers - Unity Discussions 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++)

Debug.Log("pets in database increment id " + i);
Debug.Log(“Successfully Added all the pets into the users pet index list”);

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*.PetID == petID)*
if (usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase*.PetStatus == “seen”)*
Debug.Log("seen " + i);
AddSeenPetToPetIndexList(usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase_.PetIndexID, usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase*.PetID);*_

}else if (usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase*.PetStatus == “caught”){*
Debug.Log("caught " + i);
AddCaughtPetToPetIndexList(usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase_.PetIndexID, usersDatabaseSerializer.userDatabase.usersPetIndexInDatabase*.PetID);
Debug.Log("un " + i);

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_

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