i have a script called xmlReader, which does exactly what it says: read strings from an xml-file.
now i want to declare a variable for every string, but i’m stuck at how to do that exactly.
the code is the following:
import System.Xml;
import System.IO;
var xmlString : String;
var i : int = 0;
function Start()
{
var asset:TextAsset = Resources.Load("test 1");
if(asset != null)
{
var reader : XmlTextReader = new XmlTextReader(new StringReader(asset.text));
while(reader.Read())
{
if(reader.Name == "item")
{
Debug.Log(reader.Name + " label = " + reader.GetAttribute("label"));
xmlString= reader.GetAttribute("label");
Debug.Log(xmlString);
i++;
}
}
}
}
i declared xmlString as global var in the beginning for testing so i could see if anything gets written inside the loop.
i was hoping that i could use ‘i’ as an addition to every variable name, but i couldn’t find any syntax that worked with that. i tried things like
xmlString +i = reader.GetAttribute("label");
but it’s only producing an error.
so how can i dynamically declare variables in a loop?