Stepping through XML nodes with user input

Get help using Construct 2

Post » Thu Feb 28, 2013 5:46 am

How would you step through a dialogue with an NPC, if your conversation is in XML? The screenshot is of a work in progress, but hopefully you get the gist. Would you store the dialogue text into an array from the xml first? Or can you somehow pause the file traversal until more user input is received?

Example logic:


Example data:
[CODE]
<?xml version="1.0" encoding="UTF-8"?>
<root>
<TalkToMinsc>
      <normal>
        <blocks>
            <element>
               <portrait>Minsc</portrait>
               <text>
                  <element>I'm Minsc.</element>
                  <element>I love my hamster, Boo!</element>
               </text>
            </element>
        </blocks>
      </normal>
   </TalkToMinsc>
</root>
[/CODE]
B
9
S
2
Posts: 25
Reputation: 1,050

Post » Fri Mar 01, 2013 1:18 am

I know very little about XML so the only workaround I can think of is separating the individual messages with a dash or something and using TokenAt(text,index,delimeter) to display the message, with index being a variable that is added to upon user input.
Image
B
225
S
27
G
13
Posts: 1,774
Reputation: 18,024

Post » Fri Mar 01, 2013 5:13 am

Right, that sounds like the array idea, where you bring the file data into memory for processing. Instead of arrays though, you would use a single string variable and use TokenAt to navigate it. I may end up having to do something like this if there's no way to remember where I left off in the XML file and avoid re-querying with XPath.

So then, what if your conversation looks like this?

[CODE]<?xml version="1.0" encoding="UTF-8"?>
<root>
   <TalkToImoen>
      <normal>
        <blocks>
            <element>
               <portrait>Imoen</portrait>
               <text>
                  <element>I'm so glad to be out of that place..</element>
               </text>
            </element>
        </blocks>
      </normal>
   </TalkToImoen>
   <TalkToMinsc>
       <nextDialogue>EscapeFromTheCity_Minsc_001</nextDialogue>
      <normal>
        <blocks>
            <element>
               <portrait>Minsc</portrait>
               <text>
                  <element>I'm Minsc.</element>
                  <element>I love my hamster, Boo!</element>
               </text>
            </element>
          <element>
               <portrait>MainCharacter</portrait>
               <text>
                  <element>Minsc, you and Boo are in trouble.</element>
                  <element>You have to get out of here!</element>
               </text>
            </element>
          <element>
               <portrait>ShadowyFigure</portrait>
               <text>
                  <element>I've found you...</element>                  
               </text>
            </element>
        </blocks>
      </normal>
   </TalkToMinsc>
</root>
[/CODE]Asmodeus2013-03-01 05:15:05
B
9
S
2
Posts: 25
Reputation: 1,050

Post » Sat Mar 02, 2013 11:01 pm

I think the objective here is to have an easily readable text file to edit for creating dialogues, and to avoid re-querying with Xpath just to advance from one text block to another.
B
9
S
2
Posts: 25
Reputation: 1,050

Post » Sun Mar 03, 2013 12:15 am

Why do you want to avoid re-querying with XPath? (just wondering)
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Mar 03, 2013 8:10 pm

I figured you could use a variable to track where you are in the dialog and increase the variable every time you click or press a key or whatever. This is what I came up with anyway:

XMLDialog.capx (r120.2)
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

Post » Sun Mar 03, 2013 10:15 pm

That's exactly what I'm doing now, actually.

I'm making use of XPath predicates and saving all the text for the current variable "DialogueBlockIndex" into an array.

The initial hesitation to do this was based on performance concerns, but I've since decided to just do it and see what happens.
B
9
S
2
Posts: 25
Reputation: 1,050


Return to How do I....?

Who is online

Users browsing this forum: alextro, MarkStockley and 1 guest