How do I fill an array with an XML file

Get help using Construct 2

Post » Tue Aug 23, 2016 8:30 pm

Hi, I think the question is quite simple but I haven't found a convincing answer in the manual...

I'm working on a procedural generation for a rogue-like game. I'm looking for a simple way to have rooms' presets (or assests). So I'm the generation of my world I would just have to load theses assests to create my rooms...

If you have another idea of a simpler way to make it, i would be glad to hear it.

Sorry for my clumsy english, I'm not fluent.
B
5
S
1
Posts: 21
Reputation: 419

Post » Tue Aug 23, 2016 8:52 pm

How is your xml and array arranged? What do you want to load into your array?

To parse a project file, you will need to request it with AJAX. Then On AJAX completed, you will have access to the contents in AJAX.LastData.

You can use tokenat or the XML object to pull out whatever relevant information you want to put into an array however you want or into any other data structure.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Tue Aug 23, 2016 9:08 pm

I want my array to contain the tileset of my rooms, entity's and objects' positons.
I just want to know how can I create an array-like object with an XML file.

Also, I already know a bit about AJAX and XML files, i've made a dialogue system by myself
B
5
S
1
Posts: 21
Reputation: 419

Post » Tue Aug 23, 2016 9:15 pm

Ahhh I see.

I'm not very familiar with XML myself, so someone else may be able to give better input.

I think the structure of an XML file generally lends itself to describing nested data rather than a spreadsheet like array. It would be more like an object and its instance variables. For an array, it may be better to use a spreadsheet saved as a .csv.

You also mentioned procedural generation, so wouldn't your array be generated in game? In that case, you can simply save your arrays as JSON, and load that straight back into your array. No need for XML.
Mistakes were made.
B
54
S
28
G
115
Posts: 1,705
Reputation: 65,083

Post » Tue Aug 23, 2016 9:26 pm

ok I'm not familiar with spreadsheet and JSON I will take a closer look in the manual.
But you're right my arrays aren't generated in game.
B
5
S
1
Posts: 21
Reputation: 419

Post » Wed Aug 24, 2016 6:39 pm

Ok...
I Undertsand how JSON files are structured but I didn't find: where can i load a value from a Json file?
B
5
S
1
Posts: 21
Reputation: 419

Post » Wed Aug 24, 2016 7:27 pm

If you are familiar with XML, then you know how to read value's from the XML. For that you have the XML plugin.
https://www.youtube.com/watch?v=d_LX43qQSJA

Now you just have to write them one by one in the array. During runtime, yes, that is wat coding is.

I suppose you need to alter the value's. If you just and only need to read, then there is no need to parse them in an array ?
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Aug 24, 2016 7:54 pm

Thank you but I think XML is indapted to create and manage an array with the tileset of my rooms.

I've found a plugin to use JSON file.

I'm now looking for a way to associate the value in my JSON array to the equivalant location inside my C2 array.
Fianally i see what you're saying but I need to create a C2 array.
B
5
S
1
Posts: 21
Reputation: 419

Post » Wed Aug 24, 2016 8:08 pm

B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Wed Aug 24, 2016 8:53 pm

Thank you, This is exactly what i was looking for!
B
5
S
1
Posts: 21
Reputation: 419


Return to How do I....?

Who is online

Users browsing this forum: dop2000 and 9 guests