I have a string that takes input field information and compares it with preset answers. I want to see the users input in the console, however it is just outputting System.String[ ] in the console when I call a debug.log or print. Is there a way to get it to show the text of the user input?
I can now get the number of the list item, but is there a way to get the text from the string list item. the code below gets the index location of the answer I am trying to display, say location 3, but can I call the text from index location 3 and have it print in the inspector. This code is comparing the user input to the correct answer that has been typed in the inspector, so I would assume I can get access to the text it is comparing.
public void Submit()
{
string[] userAnswers = userInputField.text.Split(',');
bool correct = false;
// if any of their answers matches one in the question/answer set, it's correct
foreach(string userAnswer in userAnswers)
{
if (currentQA.answers.Contains (userAnswer))
{
correct = true;
Debug.Log (userAnswer);
print ("User answer: '" + userAnswer + "' is correct!");
break;
}
else
{
Debug.Log (userAnswer);
print ("User answer: '" + userAnswer + "' is incorrect! The correct answer is: '" + currentOAindex + "'");
}
}
Sorry, I am lost. See image:
currentQAIndex is 3 which is the question Upper Cabinetry
Right now the console shows the useranswer and the and the number 3 for the index currently being used. But instead of showing the number of the index, I would like the console to print the text of the element, CAB UP. Is there a way to access the text, not the number.
I don’t know how you are setup. Everything is about index. If you have an array of questions with an array of answers, you’ll need to get those index.
So if you’re trying to get answer 1 and you have arrays for those, you need to access
currentQA.answers[0]. But I really can’t see enough info to help you. Just keep in mind if you want a value from a List or array, you’ll need to access it by index.
You’ll need to show more code for me to understand what some of that stuff is.
For some reason when I tried adding [0] to the end of currentQA.answers it was giving me an error. Now it works great. I have fixed the problem and appreciate your help.