Is this line of code incorrect for comparing two strings to each other?

490792463:
Seldkam
if (responseButtons[b].GetComponentInChildren<TextMeshProUGUI>().text.Equals("..."))
{
  Debug.Log("made one button uninteractable");
  responseButtons[b].GetComponent<Button>().interactable = false;
}

I am writing a choose your own adventure game and have run into an odd issue where the above does not trigger, even though the text for the "responseButtons[b]" is pretty clearly equal to ...

At least, from what I can tell. What I find most odd about this is that sometimes when the text is equal to ... it will make the button uninteractable, but sometimes it won't even though it should have.

Just wanted another pair of eyes...As you can see here, the two buttons on either side of the "Proceed" clearly say "..." but they weren't set to uninteractable! Otherwise they wouldn't be bright white and instead would be gray.

I've tried double checking that the ... problem isn't some weird copy-paste issue as I did copy paste the "..." from a website where I do my writing, but it doesn't appear to be that.

Here is the full for loop

    void DisplayTextBody(Stage nextStagePara)
{
    textToWrite.text = stage.getTextBody();
    int length = stage.getPlayerActionLength();

    for(int b = 0; b < length; b++)
    {
        if(stage.getBodyRuneStage() == null)
        {
            Debug.Log("body rune stage is null");
        }

        TextMeshProUGUI buttonText = responseButtons[b].GetComponentInChildren<TextMeshProUGUI>();

        //if the player actions of b is equal to "..." then the button should be dulled or invisible or something
       
        
        buttonText.text = stage.getPlayerActions(b);


        if (!saveScript.game_Data.getInventory().Contains("MindRune") && stage.getMindRuneStage() != null) 
            {
                
                responseButtons[stage.getMindRuneIndex()].GetComponentInChildren<TextMeshProUGUI>().text = "...";
                
            }
            
            if(!saveScript.game_Data.getInventory().Contains("BodyRune") && stage.getBodyRuneStage() != null)
            {
               
                responseButtons[stage.getBodyRuneIndex()].GetComponentInChildren<TextMeshProUGUI>().text = "...";
            }

            

            if(!saveScript.game_Data.getInventory().Contains(stage.getRequiredItem()) && stage.getRequiredItemStage() != null)
            {
              
                responseButtons[stage.getItemIndex()].GetComponentInChildren<TextMeshProUGUI>().text = "...";
            }


            Debug.Log(buttonText.text);
            if (buttonText.text.Equals("..."))
            {
                Debug.Log("made one button uninteractable");
                responseButtons[b].GetComponent<Button>().interactable = false;
            }
            else if (buttonText.text != "...")
            {
            Debug.Log("made one button interactable");
                responseButtons[b].GetComponent<Button>().interactable = true;
            }

        

    }
}

Here's it working as intendedGrayed out "..."

Seldkam

The reason why this likely occurred was because I copy/pasted the "..." from a website into the Unity inspector causing formatting issues, instead of typing the ... into the text field in the inspector directly.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related