Hello, this is my first post so apologies if I miss anything important.
I wonder if you guys might help please? I have researched this issue but cannot find a decent fix. It may be that I am using the wrong type.
Basically I wish to create an array of arrays containing Strings. But I get the BCE0048 : Type ‘Object’ does not support slicing error. I under stand that unity thinks that this is of type object but have tried many things to fix with no success.
I have removed #pragma strict but still have the issue. The strange thing is that when I created this function in a separate project (to test) it worked fine, but when plugged into the game it throws the error.
Also when i hardcode the array it works fine??
This is the hardcoded array:
var question = [
// ["QUESTION", ["ANSWER OPTION1"],["ANSWER OPTION2"],["ANSWER OPTION3"],["CORRECT ANSWER"]
["A resourceful mindset is one where \n one has the self-confidence to", "not ever make mistakes", "not take risks in order to avoid mistakes", "take risks and learn from one's mistakes","take risks and learn from one's mistakes"],
["One way to create a resourceful mindset \n is to not expect others to make decisions for you but to", "pass the decision to your boss", "take control of the situation yourself", "let others take control of the situation ","take control of the situation yourself"],
["When playing from a 10, a resourceful mindset \n accentuates the positive and reinforces that", "nothing can be gained without trying", "nothing can be gained by trying", "you shouldn't try if you're unsure about the outcome","nothing can be gained without trying"],
["Our promise to our customer, and our \n contract with them is", "Power to you", "Power to us", "Power to people","Power to you"],
["Approximately how many employees \n work for abc globally", "20,000", "86,000", "105,000","86,000"],
["How many countries does abc \n operate in globally?", "100", "12", "30","30"],
["How many customers does abc \n currently have globally?", "404 million", "120 million", "600 million","404 million"],
["How many stores does abc \n have globally", "5,000", "25,000", "15,000","15,000"],
["The majority of abc revenue \n comes from which customer segment?", "Consumer Prepaid", "Consumer Contract", "Enterprise","Consumer Contract"],
["How do we want customers to feel \n every time they interact with us \n either F2F in store, online or on the phone?", "love us", "be loyal to us", "recommend us","recommend us"],
["We need to always put customers first \n and be obsessed with going the \n extra mile to exceed", "their expectations", "their demands", "their budget","their expectations"],
["At its essence, Customer Obsession \n is to ensure that every moment of truth \n with a customer increases ", "cash", "volume", "engagement","engagement"]
//["Question", "a1", "a2", "a3","correct"],
];
But this is the controller for the question that throws the error:
import System.Collections.Generic;
import System.Text;
import System.Xml;
import System.IO;
var question = new Array();
var QuestionList;
var selectRandom:int;
function Start () {
var parsedQuestion = CreateQuestionList();
print(parsedQuestion);
var QuestionText = GameObject.FindGameObjectsWithTag("QuestionTextEdit");
selectRandom = TheRandomiser();
var theQuestion = GameObject.FindGameObjectsWithTag ("QuestionTextEdit");
theQuestion[0].GetComponent(TextMesh).text = parsedQuestion[selectRandom][0];
var answer1 = GameObject.FindGameObjectsWithTag ("Answer1");
answer1[0].GetComponent(TextMesh).text = parsedQuestion[selectRandom][1];
var answer2 = GameObject.FindGameObjectsWithTag ("Answer2");
answer2[0].GetComponent(TextMesh).text = parsedQuestion[selectRandom][2];
var answer3 = GameObject.FindGameObjectsWithTag ("Answer3");
answer3[0].GetComponent(TextMesh).text = parsedQuestion[selectRandom][3];
}
//write a function here to parse data from XML and populate an Array of questions
function CreateQuestionList()
{
// I have my xml file stored inside Asset/XmlDocs/Stock.xml
var filepath : String =Application.dataPath+"/QuestionTest.xml";
var xmlDoc : XmlDocument = new XmlDocument();
// Checking if file exist or not
if(File.Exists (filepath))
{
//loading file from Asset/XmlDocs/Stock.xml
xmlDoc.Load( filepath );
// getting the first node in xml into a list
var Quest_list : XmlNodeList = xmlDoc.GetElementsByTagName("question");
var A1_list : XmlNodeList = xmlDoc.GetElementsByTagName("answer1");
var A2_list : XmlNodeList = xmlDoc.GetElementsByTagName("answer2");
var A3_list : XmlNodeList = xmlDoc.GetElementsByTagName("answer3");
var CA_list : XmlNodeList = xmlDoc.GetElementsByTagName("correctanswer");
for (var i = 0; i<Quest_list.Count;i++){
(question as Array).Push(
[Quest_list[i].InnerText, A1_list[i].InnerText,A2_list[i].InnerText,A3_list[i].InnerText,CA_list[i].InnerText]
);
}
return question;
}else{print("FILE NOT FOUND");}
}
function TheRandomiser(){
var numOfQuestions = 2;
return Random.Range(0, numOfQuestions -1);
}
apologies for untidy code and stupid stuff i may have done, Im a learning newbie. The XML doc it references works fine and is very simple.
Thanks