Thread: Text adventure engine idea. thoughts?

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    106

    Text adventure engine idea. thoughts?

    the point of this is to relegate pretty much all game content manipulation to text files, and all actually programming stuff to some scripting language of my own invention, because I can't get LUA to link (although I know how to compile it now...).

    Anyway, I basically have two kinds of data -- global and non-global. Whenever a new game is started, the non-global data gets copied over to the player's save directory. This basically means that save/load processes are limited to folder creation and batch copying (you can do this with C++, right? I shoud look that up :P. If not, I could just have a batch-file preloader. Which wouldn't be a bad idea at all, although does BAT still take user I/O?). Anyway, I'll just copy this text file I made over.

    <
    ///###DATA INITIALIZATION###\\\

    ###ROOMS###

    A) A master list of files will be loaded from a text file in /room, which lists ever room file, in the format of:
    <
    [total number of rooms]
    room_file.txt
    room_file2.txt
    room_file3.txt
    ...
    >
    This data will be stored in a one-dimensional array of variable length. The length will be determined by [total number of rooms].

    B) Room data text files contain room name, room description, and information on which room is in which direction.

    C) Room data will be stored in a global room folder, accessed by all players.

    D) *ROOM FILES ARE NOT EDITED BY THE PROGRAM*

    ###ITEMS###

    A) Item definitions are stored in text files. They have a similar setup to the room data files. The exact information they contain is not yet decided.

    B) Individual items are stored in text files. Each text file has a name corresponding to a room. When "look" is performed in a room, the corresponding text file is read in and printed. There will probably be an option to supress being listed, and it will be stored

    C) Item definitions are not altered. Item location lists are.

    D) There are seperate non-global state files for items which can be manipulated. These are editted and non-global. The exact data they contain is not yet known.

    E) There might be global items. These will act as interface.

    ###SCRIPTS###

    A) The scripting language will be hardcoded. I might use LUA.

    B) The interpreter will also be hardcoded.

    C) Scripts are stored in a global folder.

    D) There is an events folder. This stores text files, whose names correspond to room names. These contain event queues for each room. They simply list script.txt files in a specific order.

    F) There'll also be a set of item_events. These will probably be referenced in the item state lists.

    ###ERRATA###

    A) There's an abstract "player_state" text which stores stats about the player. Whatever stats these are should be hard coded.

    B) I'm not sure how I'm storing player position. I could have a current_room room.txt which DOES get altered, in correlation to a current_room pointer.

    C) Consider an "automaton" thing for monsters or certain inventory items.

    ###SAVING/LOADING/GAME CREATION NEW###

    A) When a new game is created, the player specifies the name of the save. A new folder is created with this name, and takes all non-global data files from "default."

    B) When the game is loaded, its contents are copied to /current subdirectory. --ALL GAMEPLAY IS DONE ON THIS SET OF DATA.

    C) When a ame is saved, the data from current is copied to the folder name specified. If no folder is specified, use a default name (save?). If the folder already exists, confirm overwriting. If it doesn't, then make a new folder. Copy the contents of current to this folder. Clear current (Or not, if leaving it full doesn't cause problems).

    D) Come up with wacky file extensions to deter people from snooping.

    >

  2. #2
    lv.42 Berserker Drake's Avatar
    Join Date
    Jun 2005
    Posts
    67
    I might be the only person to put input, but I think "Go For It". I really am still learning but what you put sounds pretty neat.

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    I just can't imagine anyone would actually still play a text adventure game.
    -- Rocky
    -- DreamSys Software (http://www.dreamsyssoft.com)
    -- Free Tiff 2 PDF Library (http://www.dreamsyssoft.com/tiff-to-pdf-api)

  4. #4
    lv.42 Berserker Drake's Avatar
    Join Date
    Jun 2005
    Posts
    67
    Quote Originally Posted by rockytriton
    I just can't imagine anyone would actually still play a text adventure game.

    suzak, he is very well right. If i were you I would make something worth while because you could probably make something better than that, but, to some people, what you are doing is great practice.

  5. #5
    Registered User
    Join Date
    Aug 2003
    Posts
    1,218
    At this point in programming it is not a matter of what you think would be popular out there. It is a matter of learning as much as possible. Have a little look at this thread. As I said in there: you have to crawl before you walk, and then you have to walk before you can run. I think it is great to see people wanting to do textbased games now instead of rushing into graphical gameprogramming, only to find out that it was too hard and drop the whole thing with gameprogramming.
    STL Util a small headers-only library with various utility functions. Mainly for fun but feedback is welcome.

  6. #6
    lv.42 Berserker Drake's Avatar
    Join Date
    Jun 2005
    Posts
    67

    Thumbs up

    right on Shakti. by the way, could you look at my post on my dos menu for a text rpg here?

  7. #7
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    Interactive fiction is still immensely popular. It's also an extremely versatile genre. also, it gets around having to draw graphics, and, er, given that my primary interest is writing, I get to focus on that more.

    That, and it's not like text-based stuff is THAT different from graphics. In one, you're loading in text from a .txt file. In another, you're running IMGLoad(some.png). While there are variations specific to the API, and different methods for handling the loaded data, conceptually, stuff isn't terribly different. You're always going to be writing an engine to handle resources, and you're always going to be aiming at the most efficient and robust method.

    that aside, my method makes very little sense (Or perfect sense. I'm not really able to gauge. I like it though, but eh, relative depravation). I basically hacked out room classes and the master load list array thing. I think I'll post my source because I can't really describe it properly. Given that all the resources are just textfiles, though, it's NOT going to be a hard disk space hog, even if there are a lot of text files. 100~ room definitions is a total of about 19 kb. Also, loading them in constantly seems to be extremely quick. And since hardly anything's going to be hardcoded, modability and .exe size should both be great.

    Anyway, here's what I've got:

    http://www.rafb.net/paste/results/a5XcDx76.html

  8. #8
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Text adventures lend themselves nicely to using IDs for everything. The ID can either be it's index into the object_type array or you can use the STL and use some of the find and search functions to get the data.

    You can also use pointers to rooms, objects, etc. It's up to you.

  9. #9
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    http://www.rafb.net/paste/results/MSEvik19.html

    Okay, this is problematic. I wrote this block of code to move item entries from one text file to another text file. However, it doesn't seem to be doing that. when it gets to the point where that function is called, the program hangs. Now, reading through, it my procedure seems to bein the correct order. I'm wondering if seekg doesn't return to the beginning of the file, like I thought it did?

    After running in sum debug number, "while(read != item)" seems to be the hanging point.

  10. #10
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    Okay, question. I already mentioned that each room defintion is its own textfile. Performance-wise, though, is it more efficient to just keep loading each file via fstream on runtime, or is it more efficient to store every room definition in ONE text file, read this intoa list of string arrays, and then search through the list? I don't expect either to really have any major slowdown issues, so...

  11. #11
    mov.w #$1337,D0 Jeremy G's Avatar
    Join Date
    Nov 2001
    Posts
    704
    Traditionally a single file is where its at.
    c++->visualc++->directx->opengl->c++;
    (it should be realized my posts are all in a light hearted manner. And should not be taken offense to.)

  12. #12
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    I think I'm going to write the parser next, simply because I'd really like to be able to interface with my own software (beyond the crappy movement.cpp I'm using right now. Which consists of a bunch of ill-devised switches and random variables).

    anyway, the more I think about it, the more I realize that the difference between a user input parser is, ultimately, no different than a script interpretor.

    Anyway, back to the... script interpretor. I figure I should make my own metalanguage for this thing. It'd probably be easier to just learn LUA. However, first and foremost, I really don't need something THAT robust. I primarily need something to act as an external way to interface with the program. Effectively, they'd just be function macros. Anyway, my basic idea is to have a command follwed by the arguments it takes. I'll then read it in with getline delimit \n, and then do the same getline delimit \n on the variables, and stick them into an arguments vector or something. It... then procedes to stick something in a stack or some other STL class. I'm working on this.

    Every script command has a corresponding function. Each script function takes the argument vector. I also believe they take something else, although I can't remember what. Anyway, stuff's read out of the argument vector and plugged into varioust hings in the function. Effectively, the functions do everything, and the scripts just call them externally.

    Example, in pseudocode:

    ADD 3 5 <- In script textfile

    Code:
    function parser:
    {
       command = getline(textfile, delimit space)
       while(input string != some undecided line terminator
       arg vector = getline(gets the arugments. Delimit space)
       //some sort of checking to see which function gets called. See below!//
    }
    
    function add:
    {
       x = atoi vector[0];   
       y = atoi vector[1];
       store x+y in some sort of result buffer; <- All results will be stored in another vector. This also gets passed around.
    }
    If this sounds really freaking stupid so far, please, help

    anyway, assuming I didn't just cause everyone to go stupid with my in(s)ane ideas, and assuming I've got everything dealt with in a stack or some other STL for sequential processing... well, assuming the code is focusing on a single script command, how should I have it tell WHICH related function to load?

    The first idea I had was switch statements. This usually looks ugly, though. Also,I question their speed when they get larger. Perhaps I could figure out a way to class commands and then tier the switch (although, would that actually reduce search time?).

    The next idea involved using function overloading. However, each function's going to pretty much take the same number of args.

    erm, also considered finding a way of putting functions, or pointers to functions, or references to functions, into a cointer class and indexing it by strings, where the string is the name of the command. That's problematic in that it's probably slow, and that I don't really know if array elements can point to functions.

    Also, I think there's something I can do which also involves function pointers. The example, though, would require a switch statement to determine which... function got passed into the pointer though, so... (http://www.newty.de/fpt/intro.html)

  13. #13
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Don't bind your script directly to functions and you will thank yourself later. Try a message based approach.

  14. #14
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    Location
    Canada
    Posts
    1,034
    Quote Originally Posted by Bubba
    Don't bind your script directly to functions and you will thank yourself later. Try a message based approach.
    Do you have any recommendations for tutorials, articles, or books containing information on messaging?
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

  15. #15
    Registered User
    Join Date
    Jan 2005
    Posts
    106
    Indeed. Unless it's the process that http://www.gamedev.net/reference/art...rticle1633.asp , which involves virtual machines and op_codes, then I'm not having a whole lot of luck finding information on a messanging system.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 01-29-2008, 04:40 AM
  2. Text adventure game GUI
    By VirtualAce in forum Game Programming
    Replies: 11
    Last Post: 11-07-2007, 06:34 PM
  3. Outputting String arrays in windows
    By Xterria in forum Game Programming
    Replies: 11
    Last Post: 11-13-2001, 07:35 PM
  4. Simple Text Adventure: Need Help
    By Unregistered in forum Game Programming
    Replies: 19
    Last Post: 10-28-2001, 07:22 PM
  5. text adventure
    By BuRtAiNiAn FlY in forum C Programming
    Replies: 1
    Last Post: 09-05-2001, 09:39 PM