Stepping through XML nodes with user input

0 favourites
  • 7 posts
From the Asset Store
Total customisation of the input! You can combine inputs from all peripherals. Make your game accessible for everyone!
  • 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:

    <img src="https://dl.dropbox.com/u/7439411/stepThroughXML.jpg" border="0" />

    Example data:

    <?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>
    
  • 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.

  • 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?

    <?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>
    
  • 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.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Why do you want to avoid re-querying with XPath? (just wondering)

  • 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)

  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)