XML Horror

Discussion and feedback on Construct 2

Post » Thu Jun 06, 2013 1:07 am

Hey all,

After tearing my hair out for a while now I have decided I need the help of people who know what they're doing (at least a bit more that I do!).

What I want to do:
My basic problem is that I have an xml full of all of the variables that govern my enemy's attributes. I want to load this into an array at the start of levels. I would then spawn a blank enemy with instance variables that are populated from the array based on spawning logic e.g. spawn enemy, get type 1 stats, set animation to frame 1, off you go.

I created a mini project to test the basics of this out and I got it to work fine. Much smaller xml and array but all in the same layout and format. I tried implementing this in my main project and everything works right up until I try and do anything with parsing the xml that has been loaded.

xml i'm trying to use is:
https://docs.google.com/file/d/0B3RLm-IgrMQEX2RTVGxSdGk0WWc/edit?usp=sharing

This is the code I'm trying to use:


(https://docs.google.com/file/d/0B3RLm-IgrMQEVGN1N0ZBSjVrQmM/edit?usp=sharing)

I'm hoping it's something really dumb that I've done. I only started the xml stuff a couple of nights ago.

Any help would be much appreciated...
B
5
Posts: 14
Reputation: 403

Post » Thu Jun 06, 2013 1:11 pm

In your XPath queries, you must specify the "text()" function when you want to return the value inside a not. Otherwise, it will return the actial node.

In your ForEach Node loop, you have two actions setting the values of the array to the DATA of the node selected, right? Your XPath query does't specufy the "text()" function at the end of it. Try using "id/text()" and "health/text()". I think that should work.
B
10
S
2
Posts: 94
Reputation: 1,536

Post » Fri Jun 07, 2013 12:42 am

try load JSON file and Dictionary?
B
18
S
5
G
4
Posts: 568
Reputation: 5,079

Post » Fri Jun 07, 2013 4:21 am

+1 for .json file using the Dictionary. It's perfect for simple text. It only has a key and a value though.
B
123
S
43
G
41
Posts: 847
Reputation: 28,206

Post » Fri Jun 07, 2013 3:55 pm

Can you load a .json file into a dictionary? I thought you could only convert a dictionary to a .json.
B
10
S
2
Posts: 94
Reputation: 1,536

Post » Fri Jun 07, 2013 8:28 pm

Hey, thanks for all the replies!

I've tried adding in the text() and number() stuff but it still doesn't work. The things is though, it's even stuff like node count. If I do that in my test project it works (as well as the resizing of the array based on that). I can't even get the node count to work, even using the same xml and the same event in the two projects. one it works, the other it doesn't :(

I don't think I want to be using dictionaries for this as I will eventually have between 7 and 28 enemy types, each with ~25 variables each. I want to use the xml and array solution so that i can easily balance all of the numbers in excel and see them all in one place before saving them out to xml. It seems more scalable to search an array for an ID at X and then get all of it's values from the Ys. This means I will only need 1 function for setting any enemy's variables as long as they have the correct ID set in their instance variables. In addition, once I get this code working I want to be able to extend the same sort of thing to everything that is variable heavy in my project. Environment settings, map data, weapon variables etc.


If anyone can help me get this working I'll be eternally grateful.

I've put my test project capx here:
https://docs.google.com/file/d/0B3RLm-IgrMQEaFVVX2VzZ1JZdGs/edit?usp=sharing

And my main project here(at the end of the event sheet 'main'):
https://docs.google.com/file/d/0B3RLm-IgrMQEYThEVEpFVHlIbWM/edit?usp=sharing
B
5
Posts: 14
Reputation: 403

Post » Mon Jun 10, 2013 9:17 am

So after repeatedly trying the same things last night, and, with the events etc. looking absolutely identical, it has started working. I have no idea what I did and looking at an example that does vs one that doesn't work I can see no difference.

I'll try post a capx of it tonight for anyone else having similar problems.

Also, if anyone has the slightest idea why it just worked I would still be very interested in why this is. I hate not knowing why it works.
B
5
Posts: 14
Reputation: 403

Post » Mon Jun 10, 2013 1:54 pm

remember to delete caches and appcache in case you're exporting
B
18
S
5
G
4
Posts: 568
Reputation: 5,079

Post » Thu Jun 13, 2013 9:21 am

What does this mean?

"remember to delete caches and appcache in case you're exporting"

Where can I do this? At the moment I'm just previewing it in Chrome.
B
5
Posts: 14
Reputation: 403


Return to Construct 2 General

Who is online

Users browsing this forum: tarek2 and 6 guests