XML Horror

0 favourites
  • 9 posts
From the Asset Store
A fun horror zombie game you can upload to your website
  • 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:

    docs.google.com/file/d/0B3RLm-IgrMQEX2RTVGxSdGk0WWc/edit

    This is the code I'm trying to use:

    <img src="https://docs.google/file/d/0B3RLm-IgrMQEVGN1N0ZBSjVrQmM/editusp=sharing" border="0" />

    (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...

  • 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.

  • try load JSON file and Dictionary?

  • +1 for .json file using the Dictionary. It's perfect for simple text. It only has a key and a value though.

  • Can you load a .json file into a dictionary? I thought you could only convert a dictionary to a .json.

  • 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:

    docs.google.com/file/d/0B3RLm-IgrMQEaFVVX2VzZ1JZdGs/edit

    And my main project here(at the end of the event sheet 'main'):

    docs.google.com/file/d/0B3RLm-IgrMQEYThEVEpFVHlIbWM/edit

  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • remember to delete caches and appcache in case you're exporting

  • 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.

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