- Home /
Check if input field is something based on if a text is something
First of all, I want to apologize for the horribly named title. Basically, what I want to do is look at a text, for example it could say あ, and I want to have the player input something and the computer checks if it is right. Here's what I changed it to.
if (randomizedText.text == hir [0]) {
if (rom [0].Equals (hirToRomDictionary [hir [0]])) {
NextText ();
array.RemoveAt (temp);
attempts = 0;
} else {
attempts++;
if (attempts == 2) {
Debug.Log ("three times");
attempts = 0;
}
}
}
and
public void NextText(){
temp = UnityEngine.Random.Range (0, array.Count);
randomizedText.text = array [temp];
}
I have a bunch other but this is just one example. However, when the player gets it wrong, it still says it's right. Why?
hiraganaToRomajiImputFeild.text = "";
if (hiraganaToRomajiImputFeild.text.ToLower ().Equals ("a"))
How can that Equals
test possibly succeed? You've set the value to an empty string on the preceding line.
I honestly don't know why I didn't see that. However, sometimes, not always, it console logs incorrect when it is correct. Do you know why?
No but first off I'd try logging the value of hiraganaToRomajiImputFeild.text.ToLower ()
before doing the comparison (a in this situation I'd log it with something on either side so I could see if there were extra white space characters).
Answer by Lahzar · Feb 05, 2017 at 01:14 AM
So you are basically displaying one language, and if the player translates it correctly it will move on?
If this is the case, use a dictionary.
string display = "hallo";
string input = "hello";
Dictionary<string, string> basicDictionary = new Dictionary<string, string>() {
{"hallo", "hello" },
{"skjer", "sup" }
};
//In a function:
if(input.Equals(basicDictionary[display])) {
//Correct
} else {
//Wrong
}
Thank you for your answer. I wasn't able to fix it, so I'll try this out.