XML for complete noobs?

Get help using Construct 2

Post » Wed Mar 13, 2013 10:09 pm

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?

Thanks!
B
90
S
30
G
24
Posts: 3,189
Reputation: 32,400

Post » Wed Mar 13, 2013 10:58 pm

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.
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Wed Mar 13, 2013 11:37 pm

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.
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Thu Mar 14, 2013 1:33 am

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

Post » Thu Mar 14, 2013 2:20 am

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.

JSON:

{"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">
<popup>
    <menuitem value="New" onclick="CreateNewDoc()" />
    <menuitem value="Open" onclick="OpenDoc()" />
    <menuitem value="Close" onclick="CloseDoc()" />
</popup>
</menu>
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Thu Mar 14, 2013 2:23 am

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!)
B
6
S
1
G
1
Posts: 70
Reputation: 702

Post » Thu Mar 14, 2013 10:25 am

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

Post » Thu Mar 14, 2013 11:02 am

Didn't help you my .capx? i think my post is ignored here.
B
96
S
25
G
20
Posts: 3,054
Reputation: 22,642

Post » Thu Mar 14, 2013 12:15 pm

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

Post » Thu Mar 14, 2013 2:55 pm

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?)
B
6
S
1
G
1
Posts: 70
Reputation: 702

Next

Return to How do I....?

Who is online

Users browsing this forum: fredriksthlm, MPPlantOfficial, Yahoo [Bot] and 18 guests