XML for complete noobs?

0 favourites
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Is this method supported by CocoonJS? I think with the last update they added support for this (Full native XmlHttpRequest (AJAX) support.) but I'm not sure.

  • So there a few factors to consider here. You mention you would like to store things such as level name, level number and "game specific stuff". What sort of game specific stuff are you thinking? If you are planning on structuring your levels through XML files and then load them up on a per-level basis, it might be more tricky than it seems (eg. Saying this level has these 3 enemies of type B is pretty hard to convert into an actual object in C2). However storing things like level introduction text, random AI sentences etc. would be a good fit. So I'm curious what sort of information you would like to store?

    Some other things to consider - XML can be a pain to manage. If you are just storing simple shallow data like this Microsoft book example it's not too bad - You can manage that with notepad++. But if you are planning on having deep nodes in your XML files like this slightly more complex example it can quickly spiral out of control. Also remember that any structural changes to the XML might render entire blocks of code in C2 unusable.

    If you can post anything you can think of that you would like to be stored in XML, what problems you are hoping it will fix (that you can't do right now) and how you would like to use it game, I bet we could come up with some good examples how to structure your xml, some real-world examples to teach XML, and check if what your hoping to use XML for is appropriate.

  • Is this method supported by CocoonJS? I think with the last update they added support for this (Full native XmlHttpRequest (AJAX) support.) but I'm not sure.

    Xavier Yes AJAX it's supported on CocoonJS :)

    Make sure to set CORS (Cross-Domain Control)to hosted files before to get them in CocoonJS launcher.

    Unfortunately, CocoonJS doesn't support XML object.

  • boolean Oh don't worry, I'm only planning on storing simple stuff as you said. Game-specific stuff would be like 'number of clouds', zoom scale, etc. So I assume XML should be fine for this.

  • sqiddster Ah ok. That sounds like a good fit for XML. By keeping it simple you should be able to avoid any problems inherent to XML (eg. changing your XML structure breaks conditions in C2). I guess everyone else did a pretty good job of answering all the big questions - Was there anything left you were still wondering?

  • XML is a pain in the behind

    Just use JSON, it's easy to write and load.

    If you want a list of parameters for your level and if your parameters aren't too complex, you can use a dictionnary JSON. It should looks like that:

    {
      "c2dictionary":true,
      "data": {
        "nbClouds":20,
        "xSpawn": 102,
        "ySpawn": 503,
        "greeting": "Hello young traveler, you'll have to... blahblah"
      }
    }

    That's pretty easy to read, edit and load.

    Unless you have something more complex like a list of different enemies with different parameters... It'should be good enough.

    And well... If you DO have something more involved with a deeper arborescence, you could still do something like

    level1.json:

    {
      "c2dictionary":true,
      "data": {
        "nbClouds":20,
        "xSpawn": 102,
        "ySpawn": 503,
        "greeting": "Hello young traveler, you'll have to... blahblah",
        "enemyDefinition": "enemyDef.json"
      }
    }

    enemyDef.json:

    {
      "c2array":true,
      "size":[4,5,1]
      "data": [[
      //[     type, hp, mp,atk,mag]  <-- that's a comment
        [  "troll",100, 10, 50,  0],
        [  "witch", 50,100, 10, 60],
        ["pikachu", 70, 30, 24, 12],
        [  "demon", 85, 20, 16, 34]
      ]]
    }

    Though using the array syntax it's a bit less clear

  • I believe I saw somewhere in the documentation that you can have Dictionaries of Dictionaries, that is called a Multi-Dimensional Array. Essentially its like a database rows and columns, sounds like this is what you are looking for, but me being new to C2 not sure how to implement.

    Json and XML are very similar, just different formats, if you don't have a programmer background then it is probably for you to work with XML which is more readable.

    Brett

  • Yann that all looks good, but considering I will have a great number of levels I don't really want to save a separate JSON file for each level. I'm not saving huge amounts of data, just a few numbers and strings. Any way to have 'nodes' like in XML? and why specifically shouldn't I use it?

  • I am at the same point here. I want to store static data for my game, but my options seemed to be setting up an external file (XML, JSON) and loading it into variables or dictionary keys or just hardcoding it. I decided to go with the latter, and I just use event sheets per level to set everything up. It's pretty much the same amount of overhead, but everything is in-app, so my workflow is a little tighter. The downside is that it's less elegant to edit than a text file. It is easier to read dialog flow though, since I can see the text in the event, rather than just some key ID being set.

    The ultimate would be to allow you to set dictionary keys before run-time.

    I'd love to hear of any successful cases of an elegant C2 dialog system. I couldn't find any in my searches...

  • sqiddster

    all in one file?... doable

    {
      "c2dictionary":true,
      "data": {
        "lvl1_nbClouds":20,
        "lvl1_xSpawn": 102,
        "lvl1_ySpawn": 503,
        "lvl1_greeting": "Hello young traveler, you'll have to... blahblah",
        "lvl2_nbClouds":13,
        "lvl2_xSpawn": 251,
        "lvl2_ySpawn": 134,
        "lvl2_greeting": "Already second level! I might need to get ,
        "lvl3_nbClouds":5,
        "lvl3_xSpawn": 124,
        "lvl3_ySpawn": 162,
        "lvl3_greeting": "Ok, I'm starting to get angry!",
         etc...
      }
    }

    Then you just have to get your data from the "lvl"&curLevel&"_...." keys

  • Thanks, Yann that's not too unmanageable.

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