playMaker

Author Topic: Retrieving Text From Datamaker XML  (Read 10011 times)

Nog

  • Playmaker Newbie
  • *
  • Posts: 47
Retrieving Text From Datamaker XML
« on: March 08, 2015, 04:22:01 AM »
Hello,

What is the process for retrieving text from an XML file in Playmaker? Is it possible to use a regular text file with the dialog in it, and pull the dialog from the text file?

Thank you for any help.

Nog

Nog

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Retrieving Text From Datamaker XML
« Reply #1 on: March 09, 2015, 12:58:06 AM »
Do I have the correct format for an XML file here:
Code: [Select]
<xml>

<dialog>


<dialog01> "What is this place?" </dialog01>

<dialog02> "Who are you?" </dialog02>
<dialog03> "Hey! Wait!" </dialog03>
<dialog04> "Is this some kind of game?" </dialog04>

</dialog>



</xml>

I am able to pull dialog from the above text by using the XPath Query //xml/dialog/ dialog02. However, the dialog is displayed like this on the Unity GUI Text:
<dialog02> "Who are you?" </dialog02>

How would I go about just displaying the text without the XML handles? Anyone?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Retrieving Text From Datamaker XML
« Reply #2 on: March 09, 2015, 02:33:27 AM »
Hi,

 Check this thread, this is exactly what you need.

Typicall, you'll need to refactor your xml. It's a valid xml, but not a suitable way to describe your data:

- the dialog node hosting all the dialogxx nodes, should be <dialogs> plurial, just because it's semantically correct, it's a node that will host a number or dialog node.

-- don't put string value in quote, in xml everything is a string.

- each dialog node, SHOULD NOT have their id hardcoded in the node name, but as an attribute of child node like so:

Code: [Select]
<dialog id="01">What is this place?</dialog>

Once you have refactored the points above, you'll have the best approach for a powerful and useful xml description of your data.

now go an check the thread I mentionned above, and it will show you how to query your xml to find a node with a given attribute value and store the content into a fsmString that you can then do whatever you like with.

 Come back to me if you have trouble understanding and implemented the example in your own case.

Bye,

 Jean

Nog

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Retrieving Text From Datamaker XML
« Reply #3 on: March 09, 2015, 07:31:55 AM »
Hello jeanfabre,

Thank you for helping me. I adjusted the XML file by placing all the dialog in the attributes of the child nodes like you said, and I am now able to pull dialog from the XML and get it to display through the GUIText component using a string variable.
The XML file now looks like this:
Code: [Select]
<?xml version="1.0" encoding="utf-8"?>

<dialogs>


<dialog id="01">What is this place?</dialog>
<dialog id="02"> Who are you? </dialog>
<dialog id="03"> Hey! Wait! </dialog>
<dialog id="04"> Is this some kind of game? </dialog>

</dialogs>


I have the XML Select Single Node action and a Data Maker XML Proxy on an empty game object and a GUIText component with a Set GUI Text action on another empty game object. I declared a global string variable called Text. I placed the global string variable into XML Result and in the Text Parameter of the Set GUI Text action.

I use the XPath Query //dialog[04]/text(). As a result, I am now just getting the dialog text from the XML file. It seems to be functioning the way I want it to.

By the way, this is a good site for experimenting with XML files and learning about different types of XPath expressions:

http://www.freeformatter.com/xpath-tester.html#ad-output

Again, thank you jeanfabre for your help. I was wondering what else can XML and XPath be used for?

Thank you,

Nog
« Last Edit: March 09, 2015, 07:36:15 AM by Nog »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Retrieving Text From Datamaker XML
« Reply #4 on: March 10, 2015, 02:21:08 AM »
Hi,

 Xml and xpath are used for complex data hierarchy, and also when your data is organised in a very specific and dedicated manner, that no publishers or tools provide an adequate solution to deal with this data.

It may seems vague, and it is, make sure you read as much as you can on xml and xpath usage on the web, it's critical for success stories on complex data handling, where a database was not choosen for varisou reasons.

xml is NOT a database. Xml is a way to organize and structure your data in plain english ( VERY important), AND provide powerful scripting within your game code, which is equally important and fantastic if you think about it. this is NOT a language, this is a way to describe your data, that's all.

http://searchsoa.techtarget.com/definition/XML

Bye,

 Jean

gateway

  • Playmaker Newbie
  • *
  • Posts: 8
Re: Retrieving Text From Datamaker XML
« Reply #5 on: May 28, 2015, 04:32:21 PM »
So I stumbled across this post because I'm tasked with trying to create a dialog system that has dialog for various chrs, then decision points which then lead to other dialog.  The plan is to use playmaker + usequencer (for cut scenes camera tracking) and TextMesh Pro for text display using the set and get property functions.

With the above xml dialog I wanted to parse the data into a hash table so I end up with key values of so

1 => What is this place?
2 => Who are you?

or some way to define the chr talking

chr1 => What is this place?
chr2 => Who are you?

of course would need to probably add a name value to the xml like so ?

Code: [Select]
<dialog name="chr1" id="01">Text Value</dialog>
I would like to store these into a hash table so I can easly pull out text for the line number and chr and then play then play the animation of the chr talking and using camera cuts during this process.

ideally trying to create a dialog manager that can parse a specific xml for chrs, lines, decisions and branches..

thoughts?

I did a small video of what Im trying but no dice so far.. and im probably going about it the wrong way..

Youtube Video

Nog

  • Playmaker Newbie
  • *
  • Posts: 47
Re: Retrieving Text From Datamaker XML
« Reply #6 on: June 05, 2015, 07:48:11 PM »
Hello gateway,

I am not that well versed in XML and hash tables. I am still learning this stuff, and I have been working on other things that have detracted me from XML.

I believe that I removed the <result> tag by being specific with the text that I wanted to display. For example, I typed //dialog[04]/text() in xPath Query. That gave me the text "Is this some kind of game?" without the tags.

I hope that helps a little.

Nog