Jump to content
  • Advertisement
Sign in to follow this  
Rasmonator

Interpreting game data

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

Hi all For my first real programming project (with C++), I've chosen making a text game authoring system. The idea is to make a tag-and-script-based "language" for making games (so that you can easily make games with a text editor). When the game "code" is finished, you feed an interpreter with the text file. No fancy file formats. If anyone would be interested (ha ha), they could easily make their own interpreter. Well, my problem hasn't got very much to do with this particular project, so I think i'll just get on now: I would like to read data from a file, and then create structs/classes/whatever with data from the file. Not just create objects with data from a file, but also define completely new classes depending on what's in the file. (This is because I want to be able to define game-specific classes, like "Beverage" with attributes like "Carbonated" and "Alcoholic" if it's a game where different drinks play a big part.) How do I do this? Is there any simple way to read data, create classes and fill them with data? Or do I have to make an application that generates correct C++ source code (from the game data) and compiles it? Erm. Excuse the english and all. Thanks in advance.

Share this post


Link to post
Share on other sites
Advertisement
It's not easy, and you don't have to compile code yourself.

Let's separate the problem into two problems. The first one - how to create instances of well-known classes. For example, you have a well-known class called "NPC" and the script may order you to instantiate it. In this case you'll get it done with the abstract factory design pattern.

The second problem is how to create new classes from scratch. Well, again let's separate into members and methods. Obviously you're not going to give the user anything really complex to do; you'll need simple members of any primitive kind or a class kind, maybe arrays, and you'll need methods will just call script functions.

For solving this problem, create a class called "Container". Have this class manage a map of members and a map of methods. Think about the various things you need to contain within each member entry - besides the name you'll need the type, the value, maybe an array of values... You get the point, it all depends on the real need of your application. As for the methods - again a map will do here, while the entries in the map might point at a function in your script, or whatever is a small unit of code in the script.

Good luck!

Share this post


Link to post
Share on other sites
Dadlefish: Thanks. I think that gave me a push in the right direction.


Quote:
Original post by orcfan32
Are you going to compile stuff into executables?


At this moment, no. Why?

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!