How do I check a data from an xml?

0 favourites
  • 11 posts
From the Asset Store
DATA+ (Addon Pack)
$18 USD
20% off
Data+ is the best Data Management solution for Construct 3. It contains 4 Addons (Plugin & Behavior).
  • Hello,

    I have an XML files where i will stock the correct answear of a game.

    The XML will be organyze like that:

    <Niveau>

    <1>

    <A>open</A>

    <B>open</B>

    <C>close</C>

    <D>open</D>

    </1>

    <2>

    <A>open</A>

    <B>open</B>

    <C>close</C>

    <D>close</D>

    <E>close</E>

    </2>

    </Niveau>

    I wonder how i can extract the data to check what the player have done in the game?

    Sorry i don't find anything like that. Thanks

  • So, firstly, you need to load your XML file using AJAX. And then you can use one of the XML expressions (NumberValue or StringValue) to retrieve your data. For example: Xml.StringValue("/Niveau/1/A/text()").

    I guess you have looked on this tutorial right? construct.net/en/tutorials/read-xml-game-talk-518

    I think it does a good job guiding you step by step. But if you still can't make your game work, come back here again!

  • Thanks for your answear.

    Even if it use ajax. The game can be play offline?

  • So, firstly, you need to load your XML file using AJAX. And then you can use one of the XML expressions (NumberValue or StringValue) to retrieve your data. For example: Xml.StringValue("/Niveau/1/A/text()").

    I struggle with the XML road.

    Instead of "1" and "A" I want to put the name of the sprite in the XML line.

    For exemple i want to compare the instance variable of the sprite "1a". So it will search in the XML file the answear of 1A. But if i'am on the sprite B2.

    How i do?

  • I struggle with the XML road.

    So, if you want to understand better how the XML works, I recommend you to read the XML manual from Construct website. Then, you'll notice the following phrase from there:

    It uses XPath to access the XML document.

    Then, check this website to understand XPath. It is quite simple with lots of examples and shouldn't take you too much time.

    Okay, having said that... The XML syntax follows a hierarchical rule. When you want to retrieve a value from an XML element you need to correctly follow the path from your nested tags. For example:

    Imagine you want to get the value from the tag <A> which is within the tag <1>. Because <A> is nested within <1>, and <1> is nested within <Niveau>, you have to follow the hierarchical path. That's why the path to get the StringValue is "/Niveau/1/A/text()".

    Now...

    Instead of "1" and "A" I want to put the name of the sprite in the XML line.

    From what I understand, you would like to do this?

    <Niveau>
    	<1A>open</1A>
    	<1B>open</1B>
    	<1C>close</1C>
    	<1D>open</1D>
    
    	<2A>open</2A>
    	<2B>open</2B>
    	<2C>close</2C>
    	<2D>close</2D>
    	<2E>close</2E>
    </Niveau>
    
  • Even if it use ajax. The game can be play offline?

    Yes, but only if you are using the Request a project file action.

  • Yes that's exactly what i want to do.

    I ended with a formula like that:

    XML.StringValue("/Niveau/"Self"/text()")

    The self is probably wrong, i try different way but i don't find how type correctly the spritename.

  • Oh, okay, you can use XML.StringValue("/Niveau/" & Sprite.ObjectTypeName & "/text()")

    The "Sprite" there is your Sprite Object, just replace it with yours.

  • Me again.... I still not chaive to make it work.

    I think the problem might come from the XML path but i'am not sure.

    I try different stuff and create a text to test if it's wotk,, but no.

  • Oh, ok, there was a problem with naming rules.

    Text from the link:

    Element names must start with a letter or underscore

    So, your XML should be:

    <?xml version="1.0" encoding="UTF-8"?>
    <Niveau>
    	<A1>open</A1>
    	<B1>open</B1>
    	<C1>close</C1>
    	<D1>open</D1>
    
    	<A2>open</A2>
    	<B2>open</B2>
    	<C2>close</C2>
    	<D2>close</D2>
    	<E2>close</E2>
    </Niveau>
    

    Also, put this in a proper XML file (.xml extension), not in a .txt file.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • *Note: Your sprites names will have to be renamed as well to match the elements from XML.

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