Jump to content
  • Advertisement
Sign in to follow this  
tikiwasabi

Best way to store entity information using C#? (XML?)

This topic is 4435 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all. I'm currently tinkering around with C#, and have found myself writing a small console text game. Currently, I'm using XML to save and load monster entity information, but am wondering how I should go about storing item information. Since each monster has its own xml file, using xmltextwriter works great. But when it comes to storing all kinds of item entities in one XML file, I have no clue where to begin. Basically, I just want to use an application to create new items, and append the new code in the correct 'slot' space. Should I give up with XML for this purpose and go learn databases or something? [Edited by - tikiwasabi on June 27, 2006 6:43:49 PM]

Share this post


Link to post
Share on other sites
Advertisement
Well, considering it is a text console type game, I am sure XML will do you fine.

Here is a thread that I started a few days ago. Reading and writing a dataset to an xml file is a piece of cake. It might be overkill for what you are doing, but you could store all your "items" in a table and write it to the xml file that way. It looks a bit simpler than using xmltextwriter...

EDIT - look at the second last post.

Share this post


Link to post
Share on other sites
It also looks like your item text needs a little re-organization. Something like this might be easier to work with:


// monster...

// You don't need the big 'Item' block. You know from the Item tag
// that you are parsing an item

<Item>

// use a 'Type' tag in place of the 'Armor' block. You also don't
// need the 'Head' tag, because you specify that in the
// 'Slot' field.

<Type>Armor</Type>
<ID>1</ID>
<Slot>Head</Slot>
<Name>Ridge Racer Cap</Name>
<ArmorRating>75</ArmorRating>
<AttackPower>40</AttackPower>
<Weight>20</Weight>
<Text>RIIIIIIIIDGE RAAAAAACER!</Text>
</Item>




With this slight re-organization, you can just append new items to the end of the file (you don't have to worry about locating the Item block, the Head block, or anything like that).

Moreover, if your game is already using XML successfully for other stuff, you should continue to use it for the rest (there doesn't seem to be any obvious reason not to).

Share this post


Link to post
Share on other sites
My personal preference is to use serialization for this kind of thing. What that means is you create a class that holds the item data, and then set it up so that it can be serialized. Then serialize it with an XmlSerializer. This class will write all of the classes data to the file in XML, and read it back again when you want to. It takes all of the work out of writing and reading files, because it does it for you.

In the future you can switch serialization methods to binary serialization, and then it is significantly more compact. And while you are developing you can keep it human readable with Xml.

Share this post


Link to post
Share on other sites
Quote:
Original post by intrest86
My personal preference is to use serialization for this kind of thing. What that means is you create a class that holds the item data, and then set it up so that it can be serialized. Then serialize it with an XmlSerializer. This class will write all of the classes data to the file in XML, and read it back again when you want to. It takes all of the work out of writing and reading files, because it does it for you.

In the future you can switch serialization methods to binary serialization, and then it is significantly more compact. And while you are developing you can keep it human readable with Xml.


Good point! If anyone is interested, I could post some code from a recent lab that I did that did just that - read in an object from an XML file (rather than reading in each attribute). From what I remember, it wasn't difficult at all.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!