Efficient Text Parsing For Textadventure

0 favourites
  • 7 posts
From the Asset Store
OpenAI TTS
$10 USD
Text-to-Speech plugin.Allows your Construct 3 project to convert written text into spoken words
  • Hey,

    i was wondering if someone has an idea how to do efficient text parsing for textadventure games?

    Maybe you saw my test "game" here:

    https://dl.dropbox.com/u/45711709/INside/index.html

    While this works, it's ALOT of work to setup the events and i have no idea how to save / load the game once it gets bigger because i'd have to store all variable and group states :O

    Here is a realtime version of my parser so you can see how it works currently and what i could change / redo / add to make it better:

    https://dl.dropbox.com/u/45711709/parse.capx

    Solution: take key, unlock door with key, open door

    Thansk in advance for any input / ideas you guys can give :)

  • no one?

    where is Kyatric when you need him? <img src="smileys/smiley19.gif" border="0" align="middle" />

  • Ize,

    I was working on something like this a while back. See if this helps you (if it makes any sense): https://dl.dropbox.com/u/38038537/examples/TextParsingExample.capx

    I updated it for R102, and modified it to better match what you had in your capx.

    The solution I used was to create multiple dictionaries, one each for verbs, nouns, prepositions, and language patterns. The parsing engine only checks to make sure the string entered is valid, it does not check for game logic. The parser then passes a valid token string to a global variable, which can be used by the game logic.

    Using dictionaries makes it very easy to add verbs and such to the game, and the parser works dynamically to verify the input string, so no changes are required to it when adding words (except for the bugs I probably missed :D).

    My example doesn't have much proper game logic, but I think it should show you where I was going with it.

    I hope it helps.

    Thanks!

  • Wastrel

    I like your idea, I was trying to figure out a way to parse sentences and you pointed me in the right direction.

    I used a slightly simplified approach by using pattern sentences:

    eg.

    take 1

    open 1

    unlock 1 with 2

    The sentences the player types needs to match one of those with the numbers replaced with object names, otherwise it will say "i don't understand" or "I don't know what 'foo' is".

    Besides the parsing the game logic is made simple as possible. The command and object names are put into global variables so there are no "tokenat" expressions cluttering it up. The end result is the bare minimum number of conditions to do game logic.

    ex.

    object="key":

    --inventory has "key":

    ----set text to "you already have the key"

    --else

    ----set text to "you take the key"

    ----delete "key" from room_objects

    ----add "key" to inventory

    The room objects and inventory are dictionaries. I didn't implement it but room changing is as simple as changing the room objects. You could add room persistence by storing the AsJSON of the room objects somewhere when leaving the room. A save would consist of the room objects of each room and the inventory asJSON.

    Only about 15 events for the sentence parsing, the rest was for game content (~30 events).

    http://dl.dropbox.com/u/5426011/examples14/text_adventure.capx

  • Wow thanks alot guys, alot cleaner and easier than my approach! :D

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • R0J0hound, that is a much less complex approach. Very nice.

    My original intent was to emulate the Infocom Z-machine, which explains why my approach seems a bit overboard. :D

  • R0J0hound nice capx. I loled at the winning text :)

    Sorry Ize, I didn't get a warning for this thread. Also I don't think I would have proposed a nice solution like R0j0's.

    Adding this thread to the how do I FAQ.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)