ArrayList question

I can't figure out for the life of me why this isn't working. It seems so simple, yet I keep getting the same result.

In my script I have an ArrayList and it's filled with Tile objects. I want to get the index of a specific object. So I used the .IndexOf() function to pull the specific tile I wanted, but it kept pulling nothing. So now I'm trying to debug it using this method.

            print(tiles[4]); //This prints "Tile [ 1][1] (Tile)"

            bool cont = tiles.Contains("Tile [ 1][1] (Tile)");
            print(cont);

False is always printed. Is there something I'm not getting about ArrayLists? Am I not searching for the right thing in my Contains()?

Thanks.

Does your ArrayList contain that exact string? It's hard to tell if your print is printing some kind of object name or just a raw string.

1 Answer

1

You would need to pass in the object rather than a string.

Something like this Tile myTile tiles.Contains(myTile); //true or false

What you are seeing when you print(tiles[4]) is the ToString() function of your tile object.