XML for complete noobs?

Get help using Construct 2

Post » Fri Mar 15, 2013 10:23 am

@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.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Mar 15, 2013 1:50 pm

@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?
B
24
S
4
G
1
Posts: 244
Reputation: 3,462

Post » Fri Mar 15, 2013 3:09 pm

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:
[code]{
"c2dictionary":true,
"data": {
    "nbClouds":20,
    "xSpawn": 102,
    "ySpawn": 503,
    "greeting": "Hello young traveler, you'll have to... blahblah"
}
}[/code]

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:
[code]{
"c2dictionary":true,
"data": {
    "nbClouds":20,
    "xSpawn": 102,
    "ySpawn": 503,
    "greeting": "Hello young traveler, you'll have to... blahblah",
    "enemyDefinition": "enemyDef.json"
}
}[/code]

enemyDef.json:
[code]{
"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]
]]
}[/code]
Though using the array syntax it's a bit less clearYann2013-03-15 15:15:50
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Mar 15, 2013 3:43 pm

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
B
21
S
7
G
1
Posts: 128
Reputation: 3,076

Post » Fri Mar 15, 2013 4:21 pm

@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?
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Fri Mar 15, 2013 5:22 pm

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...
B
8
S
1
G
1
Posts: 37
Reputation: 1,326

Post » Fri Mar 15, 2013 7:46 pm

@sqiddster
all in one file?... doable
[code]{
"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...
}
}[/code]
Then you just have to get your data from the "lvl"&curLevel&"_...." keysYann2013-03-15 19:48:18
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Fri Mar 15, 2013 7:56 pm

Thanks, @Yann that's not too unmanageable.
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Previous

Return to How do I....?

Who is online

Users browsing this forum: DemantDigitalArt, Lancifer and 24 guests