In my videogame the player has to copy a text using the keyboard and the game, after checking the spelling of all the characters of all the words, updates the text to be copied in real time. So I created a List containing each charater of the text to be copied and a List containing all characters the player wrote in the input field. Then I created a series of loops to compare the two Lists character by character. These loops only have to tell me if the palyer wrote the right character, the wrong character, or if a character is missing. Here's the code i'm using:
public void ErrorCheck()
{
//The method FillList() is a simple for loop which takes a List, a string and an int n and fills the list with all the characters of the string for a number n of characters.
listOfInputChar = FillList(listOfInputChar, inputText.text, inputText.text.Length);
//Comparing listOfInputChar with listOfTextChar which was filled with the text to be copied in the Start() method.
for (int i = 0; i < inputText.text.Length; i++)
{
//If the i-th char is correct.
if (listOfInputChar[i] == listOfTextChar[i])
{
print("correct");
continue;
}
//If the i-th char is not correct.
else if (listOfInputChar[i] != listOfTextChar[i])
{
//Missing char.
if (listOfInputChar[i] == listOfTextChar[i + 1])
{
print("missing character");
}
//Wrong character.
else
{
print("wrong character");
}
}
}
//This script doesn't take in account corrections in the input field yet.
}
I call this method in Update() and the problem is this code always run the "wrong character" loop for all the characters in the listOfInputChar with index from 2 and above, even tho the characters are all right. Whould you be so kind to help me with that? Why does that happen? Thank you in advance.
↧