Load XML Data

Get help using Construct 2

Post » Tue Apr 30, 2013 9:41 pm

I am trying to create a Diablo II style skill tree. For the purpose of my initial prototype, what I want to do is have three icons organized on the left pane on the screen. On the right is an empty pane. This pane will be populated with data that is tied to the icon that is clicked on on the right pane. First off, let me explain what I do know. I've taken a look at the following tutorials:

https://www.scirra.com/tutorials/354/xml-parsing
This one taught me how to reference data in a pasted XML file.

https://www.scirra.com/tutorials/328/using-project-files-in-construct-2
This one taught me how to add a .xml file to a project.

Here's what I am trying to do:

-Load a .xml project file on start of layout.
-This .xml file looks something like this:
(EDIT: I've corrected the issues with the XML shown below based on feedback pointing out it was borked)


<?xml version="1.0" encoding="UTF-8"?>
<rows>
<row>
    <PowerName>Heavy Slash</PowerName>
    <Requirements>Long Sword</Requirements>
    <Keywords>Sword, Long Sword, Technique, Focus Builder, Accurate, Mandatory</Keywords>
    <Power>1(W),Special</Power>
    <Type>Technique</Type>
    <PlusResource>+1 Focus</PlusResource>
    <MinusResource>N/A</MinusResource>
    <Target>Single</Target>
    <Range>1</Range>
    <Splash>N/A</Splash>
    <Resist>Physical</Resist>
    <Duration>Instant</Duration>
    <Cooldown>At Will</Cooldown>
    <Description>Accurate: +5 Precision. Deals 1*Weapon Damage to target. Builds 1 Focus. If caster has no Focus at time of usage, damage is boosted to 1.5*Weapon Damage.</Description>
</row>
<row>
    <PowerName>Runthrough</PowerName>
    <Requirements>Long Sword</Requirements>
    <Keywords>Sword, Long Sword, Technique, Focus Consumer, Accurate, Mandatory</Keywords>
    <Power>1(W), +.5(W) per Focus</Power>
    <Type>Technique</Type>
    <PlusResource>N/A</PlusResource>
    <MinusResource>-All Focus</MinusResource>
    <Target>Single</Target>
    <Range>1</Range>
    <Splash>N/A</Splash>
    <Resist>Physical</Resist>
    <Duration>Instant</Duration>
    <Cooldown>At Will</Cooldown>
    <Description>Requires at least 1 Focus, consumes all Focus. Accurate: +5 Precision. Deals 1*Weapon Damage (plus .5 Weapon Damage per Focus consumed). Reduces the target's Toughness by 10 (plus 2 per Focus consumed) for 2 rounds. Actionless if user has 3 or more Focus.</Description>
</row>
<row>
    <PowerName>Defensive Strike</PowerName>
    <Requirements>Long Sword</Requirements>
    <Keywords>Sword, Long Sword, Technique, Focus Builder, Accurate, Offhand, Actionless, Accurate</Keywords>
    <Power>1(W)</Power>
    <Type>Technique</Type>
    <PlusResource>+2 Focus</PlusResource>
    <MinusResource>N/A</MinusResource>
    <Target>Single</Target>
    <Range>1</Range>
    <Splash>N/A</Splash>
    <Resist>Physical</Resist>
    <Duration>1 round</Duration>
    <Cooldown>2 rounds</Cooldown>
    <Description>Accurate: +5 Precision. Deals 1*Weapon Damage to target. Builds 2 Focus. Boosts Toughness by 10 (plus Sword Proficiency Level) until end of next round.</Description>
</row>
</rows>

-I would like some way for the action of clicking on a specific sprite, on the left pane, to tell text objects on the right pane to load specific data from one of the three power entries in the .xml file above.

What is the most efficient way to do this? I am struggling with reconciling what I've learned from the first and second tutorial I linked to above.

Thanks in advance,
Philphilzeleski2013-05-01 16:44:46
B
8
Posts: 22
Reputation: 944

Post » Wed May 01, 2013 12:08 am

First of all, your XML contains error. Some characters cannot be used in tag names. Minus and plus signs are a no go, and so are spaces.

Second, you'll have to get familiar with XPath expressions if you want to be able to fetch whatever data you want.

I've prepared a small example for you using your XML data. It displays the description for the selected power. You should be able to build upon it. Happy learning !
B
45
S
16
G
18
Posts: 845
Reputation: 13,673

Post » Wed May 01, 2013 4:06 am

Thank you Magistross. At first I was confused what you meant by not being able to use spaces and symbols. But, I get it now. That's only in tag names. I'll play around with your example and I'll re-post if I have questions. Thanks again.

Regards,
Phil
B
8
Posts: 22
Reputation: 944

Post » Wed May 01, 2013 4:20 pm

So, I've made a little progress and have been studying up on XPath. However, I haven't had much luck. What I'd like to do is to set text on a text object to be a particular line. For example, if I click on skill box sprite object 1 I want to set a text object to the first power name. So I tried this:

XML.StringValue("/rows/row/PowerName[1]")

What I end up with is the first word of the power name instead of both of them. What am I doing wrong here?

Regards,
Phil
B
8
Posts: 22
Reputation: 944

Post » Wed May 01, 2013 4:39 pm

Another question, once I've resolved the issue where I can pull up the whole name of an entry how do I change the display text in case I want to append text to what I am querying?

For example. I want to pull up the contents of the first Requirements tag, but I want to display it as "Requirements: (contents of the first requirements here)"

Thanks in advance,
Phil
B
8
Posts: 22
Reputation: 944

Post » Thu May 02, 2013 4:40 pm

Sorry to bump this thread, but I am still hoping to get a response.
B
8
Posts: 22
Reputation: 944

Post » Tue May 07, 2013 8:51 am

@Magistross

Thanks for sharing sample file well I wana to know how to save our file in XML Forment.

Thanks
rob2013-05-13 11:07:09
B
12
S
2
G
3
Posts: 57
Reputation: 3,439

Post » Tue May 07, 2013 4:00 pm

@philzeleski

Sorry for the late response, you should the "@username" trick so your correspondence know they have a message waiting for them !

The XPath that qualifies the first power's name is actually this : "/rows/row[1]/PowerName"

You should rename your "rows" tag to "powers" and "row" tag to "power", it'd make more sense that way !

Now for your second question, simply set the text to :
[code]"Requirements: " & XML.StringValue("/rows/row[1]/PowerName")[/code]

@rob

I don't understand what you actually want. Could you explain it a bit more ?
B
45
S
16
G
18
Posts: 845
Reputation: 13,673

Post » Mon May 13, 2013 11:04 am

@Magistross,

Thanks for asking.

Yes Sure actually I want to save my game in xml format. is this possible in c2........

I have created a game in C2 and and export their file in xml forment

rob2013-05-13 11:09:38
B
12
S
2
G
3
Posts: 57
Reputation: 3,439

Post » Mon May 13, 2013 11:22 am

http://www.youtube.com/watch?v=d_LX43qQSJA

And you can't really write xml using the XML plugin, it's only for xml parsing.

You would have to build the xml yourself via events.Yann2013-05-13 11:23:33
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 26 guests