Item in array being called instead of other one

Hi, I’m trying to figure out why an item in an array is being called instead of the intended one.

When a player presses a button it will add the name off that button as an item in an array.
When a player presses a button to remove that item from the array it will check the index, and within the index runs a contains with the items name. If true it will then remove that index.
I have a system where each item adds points when you click them. then when you remove them it takes away that same amount of points.

My problem is the two items in the array have very similair names as they as the same character but with a certain item. So currently one is called “Tzaangor Enlighted” (90 points) and the other is “Tzaangor Enlightened (On Disc)” (210 points)

When trying to remove the version of the disc is will remove the index, however it will only take away 90 points instead of the 210 that it should. Therefore it’s calling the action for the non disc version first.

Is this because the name both start the same? Is there a way I can do this without changing the name?

many thanks

Contains (string) only checks if the string contains the value specified, regardless of any other characters in the string (before or after the specified ‘contains’.) Since “Tzaangor Enlightened” is technically in both strings, and the one that removes 90 is called first, your function will only call the first one, every time regardless of which “Tzaangor Enlightened” it is. Instead of contains string I’d use String == string (exactly). In that case you’d want to make sure you use exact spelling for every time you call that index value to check for Tzaangor Enlightened -(specific variant)-. But it should work that way

1 Like

Hey man,
This worked perfectly thank you so much! I originally thought the contains was completely text sensitive like the == you’ve just shown but it makes much more sense. So I can use the contains just to check if any of that specific race is still alive, while using the == to check if that specific model is still alive.

Really appreciate your time
thanks

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.