Load XML Data

0 favourites
  • 11 posts
From the Asset Store
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • 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:

    scirra.com/tutorials/354/xml-parsing

    This one taught me how to reference data in a pasted XML file.

    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,

    Phil

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 !

  • 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

  • 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

  • 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

  • Sorry to bump this thread, but I am still hoping to get a response.

  • Magistross

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

    Thanks

  • philzeleski

    Sorry for the late response, you should the "@username" trick so your correspondence know they have a message waiting for them ! <img src="smileys/smiley2.gif" border="0" align="middle" />

    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 ! <img src="smileys/smiley2.gif" border="0" align="middle" />

    Now for your second question, simply set the text to :

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

    rob

    I don't understand what you actually want. Could you explain it a bit more ?

  • 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

  • Subscribe to Construct videos now

    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.

  • Yeah, as Yann said, the XML object cannot be used to create an in-memory XML document... I wonder why too !

    But nothing keeps you from writing your own XML string ! You could then output it as a file download using the FileSaver plugin.

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