Sign in to follow this  

Generating and initializing content for a text RPG

This topic is 823 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

Point me in the right direction, please!

So, I've got a basic (albeit, over engineered wink.png ) text-RPG system down. Rooms, with characters inside of them, and items inside of those. Characters can move, interact, get items, etc. There's a class that parses player-input-commands and is imported by the main game loop—so the basics are there. Now that I have all the basic systems down, I'd like to start creating and storing the world, but am at somewhat of a loss as to how to do this.

 

I'm using C++, and can think of several things:

  • Hardcoding the creation of each object and its containers in C++. For testing purposes, this is working for now, but it's not a long-term solution
     
  • An SQL database - which I really want to use, just because I think it'd be a good learning experience). This would require learning a C++ interface for SQL (or maybe a non-SQL database like MongoDB). I'm looking at SQLite now.
     
  • Text files - which I don't want to use, but might be easier. I'd do something like have a "Rooms" file, a "Characters" file, and an "Items" file or something. I'd then have to figure out a way of getting C++ to read the appropriate lines from these files and use them to instantiate the respective objects
     
  • JSON, XML, etc. - which I don't fully understand, but think it's something that turns strings into numbers for easy storage and recalling. Might it be the interface through which

Rooms will probably have to be hard "coded" at first (until I get to random-room generation!)  Items and characters (i.e. - monsters) I'd like to randomly generate. 

So, what do you guys use, and how do you use/implement it? 

Edited by AmagicalFishy

Share this post


Link to post
Share on other sites

I personally would use JSON for this if I were implementing it today (In the past I might have used XML). You might want to learn about XML and JSON before looking at DB based solutions (which might be overkill for your application).

 

http://www.w3resource.com/JSON/introduction.php

 

The key thing here is that your rooms would have some sort of identifier (ID) that you could use to jump between them.

 

For example if you had a room called "Castle" and one called "Moat" then you could have an entry "South" that told the game engine to go to the "Moat" room.

 

There are a number of libraries available for C++: http://www.json.org/

Edited by shadowisadog

Share this post


Link to post
Share on other sites

I also think that using a database for this is going to be an overkill and another con.:
You may find, that using a relational database like SQL to be too rigid for something like that type of data. I'm not saying that it is not possible to design a good entity-relation database model for rpg items and monsters, on the contrary, it can be done, but doing it right is a lot of work!

If you think about it, most of the items and monsters have something (or many attributes) unique to them. Yes they have a lot in common, like the main properties, health, strength and how knows, but almost all of them has something extra non present in the others (fire damage, extra health, providing teleport skill, etc...). A simple database model will not allow you to have something like this easily.

For this setup a pure data or prototype based model is much better and this is better supported by XML and JSON.
Both are "simple" text based human readable formats with an armada of tools and third party libs.

Good tips on choosing an XML parser (do not roll your own, only if you are really interested, but it is unnecessary/boilerplate):
http://stackoverflow.com/questions/9387610/what-xml-parser-should-i-use-in-c

json.org has a good list for JSON.

Share this post


Link to post
Share on other sites

Have you seen this?:

 

http://rapidjson.org/md_doc_tutorial.html

 

Every programmer has to fight syntax and "flounder around" at some points. It is part of it. Whenever you don't really understand the way something works it is going to be hard to work with. You may want to consider switching json parsers or perhaps switching languages. C++ is a notoriously difficult language to use/learn especially for people just starting out.

Share this post


Link to post
Share on other sites

the more languages you learn the easier it becomes.

 

i learned my first language in 1978.  now, 37 years later, i can pick up a typical new language in about 2 weeks.

 

syntax changes, but coding concepts remain the same: mathematical operations, calling subroutines, looping, branching, memory allocation, etc.   remember, at the end of the day, no matter what language you start out with, it all turns into machine code for some particular processor family's instruction set, or some sort of pcode executed by a runtime module compiled into that same machine code language.

Edited by Norman Barrows

Share this post


Link to post
Share on other sites

You could look into creating  your own binary files for storing world information.

 

There's an excellent article here for doing this. Even if you don't go down this path, I highly recommend it in case you ever need to interface with binary files

Share this post


Link to post
Share on other sites

SQLite could be quite an interesting solution. It's a single library you link to your C++ binary and lets you run SQL at a database which lives in a single file.

 

You could therefore write an SQL script which sets up the database as part of your build process.

 

The player "starting" the game then means that your app just copies the original master datafile and opens the copy for the player to work with. "Saving" the game consists of closing the SQL connection (to make sure all the changes are committed) and copying the file and reopening the SQL connection and then carrying on.

 

One of the interesting aspects of this is that can manipulate the database "behind the scenes" to help you debug it; because you can just open it in another SQL session and query what happened to those objects when you ran that command.

Share this post


Link to post
Share on other sites

+1 for SQLite

 

Having worked on many text based MUDs in the past the one thing that holds true is that the easier it is to manage the data the better because the content is your game.

 

A few reasons I like SQLite:

- the callbacks for executing queries map nicely to constructing objects (1 row - 1 object)

- ACID compliant - you would be surprised how often this can be an issue

- in a text based world, SQL is just plain useful.

- SQLite has a lot of external editors that - to me anyway - are much more suited for structured text / game data

- If you outgrow SQLite you can very easily move data to nearly any larger SQL database

Share this post


Link to post
Share on other sites

This topic is 823 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this