A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Game: Importing inventory items - .xml or .as?

  1. #1
    Member
    Join Date
    Sep 2010
    Posts
    37

    Game: Importing inventory items - .xml or .as?

    Hey guys.

    I'm working on creating a flexible and reusable OOP RPG system, with characters, stats, items and so on.

    As I plan to be able to create and import as many items as one would want in such a game, a big question that has come up is how to best store the various items' names and effects.

    Say i have a Party Class, which contains a character object/array, and a Inventory object/array.
    Say i open a chest and call party.inventory.addItem( new Item("Boots", 1);

    the Item Class is a base class that is usually extended into differrent classes like Weapon, Armour or UsableItem, with appropriate properties for each.

    SO; how could i best store these "items" before i add them to the inventory?
    store them in a single xml, or one xml for each item type (weapon.xml, armour.xml), or do I create a single .as file with all the existing item objects to possibly choose from, or one .as for each type of item?

    This based on the stats for a Weapon item for example being:
    name:String = "Bastard Sword"
    power:uint = 12
    class:String = "sword"
    attackType:String = "physical"
    pic:String = "com/rpg/items/bastard_sword.png"
    (also, is that the best way to go? Having external images for items? Having separate movieclips for each item with a different picture seems, frankly, ridicilous)

    I've looked around but can't find anything in regards to flash on this subject.

  2. #2
    Member
    Join Date
    Sep 2010
    Posts
    37
    no one has any advice or experience with stuff like this?

  3. #3
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    As with most things, there are many ways to approach this. The right answer for you depends on some factors you didn't include. But I'll tell you that .as files are NOT the right solution. They are not the right solution because you cannot load a .as file as a class at runtime, and if you're talking about including everything at compile time, then you're not talking about .as files containing your data, but really classes.

    In general, I'd suggest separating your data from your program. That means some conceptually external data source. Whether you load from it at runtime or bundle it in at compile time doesn't make much difference.

    XML is a perfectly valid approach, though perhaps a little verbose.

    Are you loading these at runtime, or are you bundling them into the swf?

  4. #4
    Member
    Join Date
    Sep 2010
    Posts
    37
    Well, I'm sorta learning a bit as i go along here, but the idea is to bundle everything in to the swf at compile time so the game can be run from that single file, by sites like newgrounds.

    You say XML is a valid approach, but a bit verbose. What could be a better solution?

  5. #5
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    How structured is your data? If it's just name/value pairs, then you can use a URLVariables style thing.

    XML is fine. The verbosity only comes into play when writing it and when transmitting it. If you compile it as an asset in the swf, then it'll get zipped along with everything else and it won't unduly add to the size of the swf. Writing it can be annoying, but there are several editors that help with that. Take some time and work out your entire structure, use small but unambiguous node names for convenience.

    The other, less verbose, alternative is JSON. As3corelib has a JSON decoder. And if you ever decide to serve new data from a server, it would be very easy for the server to generate either JSON or XML.

    Since you are planning on compiling everything in and having a fairly small number of items, you could create classes for each. Be sure to take advantage of Interfaces and inheritance. You'll need classes for items anyway, but if you're loading separate data, you'd have something like Sword which is parameterizable, rather than BastardSword with everything built in. Either way, you'd want a Sword class which implements all the Sword specific logic. You'll probably want a Weapon class too, etc.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center