Generating and initializing content for a text RPG

Started by
11 comments, last by Alpha_ProgDes 8 years, 7 months ago

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?

Advertisement

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/

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.

Blog | Overburdened | KREEP | Memorynth | @blindmessiah777 Magic Item Tech+30% Enhanced GameDev

Thanks, guys.

After a lot of research, and some benchmarking I've decided to go with rapidjson.

Now to figure it out!

I'm spending a ton of time floundering around, struggling to get syntax correct—and not actually learning anything. sad.png There is a distinct lack of good, succinct tutorials.

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.

That particular website has helped me out a lot, actually!

I've been programming for ~4 years indeed, so I understand the floundering around (though I only started w/ C++ a couple of weeks ago).

But god damned do I hate it.

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.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

Whoa. What language was it, if you don't mind my asking?

Just to clarify, "I hate it" referred to hating the floundering. I love C++ !

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

This topic is closed to new replies.

Advertisement