XML is a godsend

Get help using Construct 2

Post » Wed Apr 18, 2012 1:54 am

Awesome new release, guys! Funny enough, I was hoping for XML support for reading text from a file; just what I needed for a text-based game! However, how do you get it to work? I feel kinda dumb asking, but how do you get the text file to read your XML file? Or do you import the XML file into the project? I'm a little lost.
B
11
S
3
G
5
Posts: 10
Reputation: 3,514

Post » Wed Apr 18, 2012 2:00 am

Try using the AJAX object to request an XML file, then load it in 'On completed' by loading AJAX.LastData in the XML object.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Wed Apr 18, 2012 2:09 am

Please please please make a json object capable of traversing complex objects! If not, I'll have to make one (that uses expressions like jquery) myself :(
B
35
S
8
G
8
Posts: 532
Reputation: 6,868

Post » Wed Apr 18, 2012 3:01 am

Uhh...I think I'm still a bit lost. I have a sample XML file:

[code]
<?xml version="1.0" encoding="ISO-8859-1"?>

<script scene="ep01_scene01">
     
     <main_line line="1">
          <character>Leroy</character>
          <text>Wakka wakka, folks!</text>
     </main_line>
     
     <main_line line="2">
          <character>Leroy</character>
          <queue choice="1"></First>
          <queue choice="2"></Second>
          <queue choice="3"></Third>
          <text choice="1">I am saying the first selection.</text>
          <text choice="2">I am making the second selection.</text>
          <text choice="3">The third selection is mine to make!</text>
     <main_line>
     
</script>
[/code]

I have an AJAX object in my scene, and I make the request on start of layout. In fact, here is my event sheet:



Thing is, I'm a bit confused as to what I should be doing here.
B
11
S
3
G
5
Posts: 10
Reputation: 3,514

Post » Wed Apr 18, 2012 3:09 am

Event 10 => Load XML document from string AJAX.LastData
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,998
Reputation: 57,791

Post » Wed Apr 18, 2012 3:10 am

@Sharpshooter, where you have the "????", have you tried entering AJAX.LastData there?

And yep, this is most definitely an awesome addition to C2, so much simpler having it all built into the core.

[Looks like Kyatric got to it just a minute before I did, must've been right as I was reading it!]Ugotsta2012-04-18 03:11:07
B
126
S
7
G
4
Posts: 185
Reputation: 7,233

Post » Wed Apr 18, 2012 3:31 am

Ok, I got that. The last question I have is how do I get the text object to be set to a specific node in the xml file?
B
11
S
3
G
5
Posts: 10
Reputation: 3,514

Post » Wed Apr 18, 2012 2:02 pm

You have to use XPath - try looking up a tutorial on it.
Scirra Founder
B
359
S
214
G
72
Posts: 22,949
Reputation: 178,544

Post » Wed Apr 18, 2012 9:25 pm

Well, I understand the XPath part. What I'm having trouble with is how you get Construct to actually recognize when I call a node; my issue is that I just don't understand where I put the expressions for XPath; do I just stick them in the "set text to" area or...?

I am confused in making the XML file communicate with Construct 2.
B
11
S
3
G
5
Posts: 10
Reputation: 3,514


Return to How do I....?

Who is online

Users browsing this forum: BinaryPanda, MarkThomas and 21 guests