I’ve had a thorough look at the tinyxml (C++) tutorial but still can’t really understand how I apply the examples to what I’m trying to do. What I’m trying to do in short is use an xml to generate a series of room objects in a game. Is someone able to give me a short example with the following xml and Room object, please? Xml is:
<room>
<name>Prison room</name>
<connections>
<connection>Guard room</connection>
</connections>
<items>
<item>
<name>Short sword</name>
<attack>2</attack>
<armor>0</armor>
</item>
</items>
<monsters></monsters>
</room>
Room object has the following fields:
std::vector<Item> itemsInRoom;
std::vector<Room> connectingRooms;
std::vector<Monster> monstersInroom;
std::string roomName;
Thanks in advance!
Edit: Removed the edit as that particular problem was solved.
The first thing to do would be to learn more about XML and about representing/structuring/abstracting data. For example, it is usually unwise to encode e.g. the item “short sword” inside the room as you do. Rather you would want to provide a definition of that item (or a template of it) somewhere else and only have a reference to that, possibly with some extra parameters inside the room node. You will probably also want to learn to use attributes (all data is not the same, some data should be attributes).
Once you have groked that, the actual TinyXML stuff is easy. TinyXML is about as simple as it can get:
TiXmlDocument, give it the name of your data fileLoadFileon your document objectFirstChildElement, giving you the root node (note that if you have more than one room in the XML you need to have a separate root node!)FirstChildElementandNextSiblingElement.FirstChildElementandNextSiblingElementin the same manner as for the room nodes for “anything inside” each room (whatever you decided that may be) to figure out what each room looks like and what’s in them. You must know what this data means, TinyXML cannot know this kind of thing, it merely provides you with structured data.<door to="guard_room" x="5" y="3" status="locked" />create the necessary links so your game reacts appropriately.(and don’t forget to check for errors)
The tutorials at the TinyXML site are also very easy to understand (last I looked some 2-3 years ago, you could basically copy-paste them). If these really pose a considerable problem, I’d reconsider the idea of writing a RPG for the time being. I’m not saying forever, but at least until you have enough experience to follow these.