XML for complete noobs?

0 favourites
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • Hey everyone,

    I'm about to start level development for my game. The game will have quite a few levels, and each level should have certain information associated with it (Level name, level number, game-specific stuff, etc.)

    Since populating arrays/dictionaries manually in C2 is a pain in the behind, I thought this may be a good time to try out some XML. However, I know zero javascript and a laughingly basic level of HTML, and obviously no XML. I've looked into it but getting started seems a little scary!

    Is there a way for me to learn everything relevant to the very simple task I want to achieve?


  • http://dl.dropbox.com/u/76227787/ajaxml.capx

    Open .xml file in Files folder on project tab and you observe differences between event sheet and xml file.

    Have fun.

  • I'm pretty sure that for loading your levels into dictionary, you could convert your xml into json, and then use the dictionary classes method to load the json info into the dictionary.

    The conversion from xml to json is trivial if you google it.

    As for the other part, The Dictionary Manual Pageshows an action to read from JSON, so I would try that.

    To see the format to use, make a tiny dictionary, and save it to json, then convert that to xml and see how it looks, then build backwards from there.

  • Sorry for being a complete noob - but what's JSON and where does AJAX come into it?

    All I really want is an easy-to maintain table of values.

  • JSON is another set of letters, like XML. It doesn't really matter what it is =P But for your sake, make a new construct program, and add a dictionary. Then make some events to add your key values to the dictionary (just a few). Then do something like: On condition (finished filling dictionary (or whatever)) -> Dictionary.DownloadJSON.

    That will download a JSON file to your computer. Use a text editor and open it up and see how it is structured. It is structured simply, but I'm not precisely sure how in this case. Once you see it, you can replace the key/values you used for this demo with your REAL key value pairs, and load it into your game via the dictionary object's LoadJSON function.


    {"menu": {

    "id": "file",

    "value": "File",

    "popup": {

        "menuitem": [       {"value": "New", "onclick": "CreateNewDoc()"},       {"value": "Open", "onclick": "OpenDoc()"},       {"value": "Close", "onclick": "CloseDoc()"}     ]



    The same text expressed as XML:

    <menu id="file" value="File">


        <menuitem value="New" onclick="CreateNewDoc()" />

        <menuitem value="Open" onclick="OpenDoc()" />

        <menuitem value="Close" onclick="CloseDoc()" />



  • As for AJAX, it is a method for getting information to and from a web page asynchronously. In other words background transfer of information.

    If you find your program takes forever to load, perhaps then AJAX will be a useful addition, but for the moment, getting your levels to load at all might take precedence. Function, then Faster!

    (@Squiddster Love your art btw!)

  • OK, thanks cincipon ! I have just one more question.

    I know dictionaries handle pairs of values, but what I'm really looking for is a table of values - i.e. each level will have associated with it a name, sequence number, etc.

    Is there any way to do this with dictionaries as with your method? Or will I have to do something else?

  • Didn't help you my .capx? i think my post is ignored here.

  • Joannesalfa, I just didn't understand why AJAX would be needed in this case. I took a look at your capx but I didn't really understand what it was trying to do.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • From your example it seems like it'll be fine, unless you have some more complicated relationships you haven't mentioned. You can use each level's dictionary object as a row in your 'table', and the key/value pairs in each dictionary will be the columns.

    QUOTE --> (i.e. each level will have associated with it a name, sequence number, etc.) <---QUOTE

    If this is as complicated as it gets, then each level could be loaded into a dictionary, either one dictionary that you clear and reload on each level change, or a dictionary for each level if that works better (no clue here).

    If your data is more complicated than that, then perhaps if you post a tiny example we can come up with something that'll handle it.

    It's a shame you can't just make a dictionary of dictionaries! (Unless you can?)

  • Thanks cincipon , I guess I'll just have to play around with it a bit.

  • AJAX is used to get a xml file in wherever.

    Didn't you see a xml file in files folder? it's very easy and it's weird anyone couldn't understand my .capx

    Try to run preview, then open aj.xml in C2, change the numbers to balls and speed whatever you want, then try to refresh browser (do not click preview again in C2) you will understand.

    It would work with levels if you try to experiment. Dictionary is just a database of values.

    It's designed to update the game WITHOUT editing in C2. Especially for anyone who don't have C2 can edit the game.

    I made a post to you according to this thread title "XML for complete noobs" my .capx will explain you how XML works.

    Sincerely, if you really want to learn how to use XML, then the result is your ignorance seems rude, i wouldn't to help you again.

  • Joannesalfa

    I sincerely apologize - I just downloaded your capx again and realized what it did. The first time I looked at it I didn't notice the XML file and I was put off by the AJAX as I thought it involved web connectivity, etc. I was also put off by the red balls - when I ran it I thought they were in rows and I didn't see what they meant. Again, my fault for not looking into it enough at the time.

    Thanks so much for your help mate, now that I know a little what I'm doing it helps a lot.

  • Thanks for your consideration!

    AJAX is called "Asynchronous JavaScript and XML" It can relate to XML where to get the values from any place.

    I would explain you again in different way...

    This .capx is basic one how to use XML, if you see:

    <ball category="RED">




    Ball Category RED, i didn't implement an event to pick "Category", it's an idea where to pick an object.

    Count is 4, it means it could spawn 4 balls, if you change 4 to 10, it will spawn 10 balls.

    Speed is 200, it's currently bullet speed for red balls.

    If in case AJAX fails, you can add extra events to default values.

    I hope you master XML.

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