Quantcast
Viewing latest article 2
Browse Latest Browse All 4

Answer by Flimgoblin

If you use the parser that you linked to you can do something like:

public var dialogueXMLFile:TextAsset;
public var dialogue:XMLNode;

function Start(){
   var parser=new XMLParser();
   dialogue=parser.Parse(dialogueXMLFile.text);
}

You can then access your dialogue as:

Debug.Log(dialogue.GetValue("scene>0>actor>0>line>0>_text"));
Debug.Log(dialogue.GetValue("scene>0>actor>0>line>1>_text"));

(though the arrays start from 0 rather than 1 unlike your ids in your XML document)

If you want to loop through the dialogue you can do:

for(var n:XMLNode in dialogue.GetNodeList("scene>0>actor>0>line")){
         Debug.Log(n.GetValue("_text"));
}

Complete script I'm testing with:

public var dialogueXMLFile:TextAsset;
public var dialogue:XMLNode;

function Start(){
   var parser=new XMLParser();
   dialogue=parser.Parse(dialogueXMLFile.text);
   Debug.Log(dialogue.GetValue("scene>0>actor>0>line>0>_text"));
   Debug.Log(dialogue.GetValue("scene>0>actor>0>line>1>_text"));

   for(var n:XMLNode in dialogue.GetNodeList("scene>0>actor>0>line")){
         Debug.Log(n.GetValue("_text"));
   }
}

Viewing latest article 2
Browse Latest Browse All 4

Trending Articles