Dark Forest Crow Notes - Interactive fiction, text-interactions based and roleplaying games

Saturday, July 23, 2016

Modern text-based adventure games development #3: Solutions

    Time for another post of thoughts. Previously we discussed problems that are common for modern (and not only) text-based adventure games development. Again, this is not a tutorial. I'll write some tutorials for those who are planning to develop their own games later (yes, there are tons of such tutorials already on the internet so hopefully I will change my mind and will not do that).


Looking at fellow developers that suffer from poor development tools

So, text-based adventure games usually have such problems:

1.) Poor natural language processing capabilities.
2.) Primitive gameplay and game mechanics in general.
3.) Primitive characters or even no 'real' characters at all.

    Why is it so sad? I think the roots of these problems are in interactive fiction community ideology that is obsolete. Ken Poirier from a comment section on our facebook page also added that one of the problems with text parsers is that games are often designed to be compatible with the old z-machine system. Well, this is one of the reasons. You can read about z-machine here.


    All things listed above can stop you on your way to creation of your unique text-based game. So, what can you do about that?


    Again, if you want to create simple ('traditional') interactive fiction game as fast as possible - take a look at Twine or Inform and come back later. You can also skip everything below for now.

    I see only one way of text-based games development that can help you achieve good results without forcing you to study things you will never use again:


    You can develop your text-based game like it's a real game. Yes, strangely, but text-based games are computer games too, so you can just...program text-based games using any programming language you know. This is the only way to create something really unique and the only way that gives you complete freedom in your creativity, as well as useful experience, knowledge and portfolio.


    You may think 'but why do I need to create everything from scratch and create yet another set of crutches?', and I am ready for that.


    Below are some ideas about text-based games in general. Text-based games are simple (if we talk about development process) - you don't need graphics with outstanding landscapes or cute pixel 

art characters, you don't need marvellous music, you don't need top-notch voice acting - just something that allows you to print text on the screen. And maybe a good compelling plot. Maybe.

    Let's pretend we want to create a text quest or any kind of interactive fiction. If you played some text adventure games you could see that usually the gameplay of such kind of games goes in this way: 


    Process input text-> Display output text -> Repeat

    Actually, that's all. 


    So, do we really need some special software tools like Twine, Adrift or Inform to create such a game? A lot of people are working right now developing these tools to help you to do what exactly? - request user input via text field, process (in a very simple way) received input and then just display a response.


    That's all. Literally. 


    If you need something advanced - these people and these tools will answer you 'sorry, mate, we can't do that, do it yourself'.  Maybe they can offer you natural language processing? - No, of course no. Easy-to-implement ways to create game world that is more complex than connected rooms? - No. Tools to create your NPC with replics, emotional state, memory? - You know the answer.

    You may think again (I see you like to think) 'But actually you can simplify any kind of games in this way. Crysis processes some inputs, analyzes it, displays some korean soldiers, then you hear pew-pew and that's all'. No. It's not that simple: you need graphics engine, 3d models, you need sound libraries, you need voice acting, you need animations, you need physics, you need math, you even need artificial intelligence...Not that easy to create everything solo.

    I am just saying that fellow reader can create text-based games from scratch using any programming language with it's basic functionality.


    Text-based game usually takes input strings and displays strings as answers based on some conditions. For example, your game can have such kind of conditions: current game zone, player's stats, completed quests, previously received input strings, game difficulty settings, current input string.


    Then, if your game receives 'How are you, friend?' input string, it displays output string 'Go away, animal!' doing something like this:

if (player is in zone1)
  if (player's charisma is equal to 1)
    if (player completed quest 'Have sex with Bishop's wife')
      if (previous player's replic was 'Hello, mister Bishop!')
        if (current input string icontains 'how are you')
          if (difficulty is equal to 'hardcore 18+')
            do_some_stuff(x)
           display("Go away, animal!")
          else
           do_other_stuff(y)
           display("Go away, retarded sickfuck!")

Just a bunch of simple if-clauses. Looks ugly. But this is the example of what is actually going on when you play any game - it receives some input signals and based on that signals and some constants and variables produces output:

if (variable1)
  if (variable2)
    ...
      if (variableN)
        do_simple_things()
        set_some_variables()
        display(x)

    Of course you will not write code like that. Well, if you are new to programming, you can even start with this code. In case of text-based games the amount of if-clauses is not huge. Good object oriented design will eliminate the need of this stuff and checks will be hidden. How to reduce the amount of explicitly-written conditions and write good object-oriented/meta abstract code for videogames? How to create your own game world model? What about roleplaying system? Items, objects interactions? Eventloop? Topics that are already covered in myriads of artices. But actually you can do that, and the process will be easy since it's just a text-based game. You'll still be able to focus on storytelling, replics and descriptions of things (usually it's 90% of interactive fiction development). And the development experience of doing these simple things yourself (even if you think that you produce worst code in the world) will be priceless. 

   What about natural language processing? I'll definetly write an article about some simple and useful algorithms you can use. The simplest thing you can do right now to improve players experience is to introduce synonyms checks and even simple regular expressions checks. That's right, son, don't just write 

    if inputString is equal to 'go north'

write 

    if inputString matches setOfRegexps

where setOfRegexps contains things that match 'I go north', 'I fuckin want to go north', 'I go to the north', 'I run north', 'I jump to the north'.

This is possible solution too:

    if inputString.icontains(mapOfSynonyms['go']) && inputString.icontains(mapOfSynonims['north'])

where mapOfSynonims is a map/any data structure that contains sets of your synonyms: [{'go', 'run'}, ['north', 'N'}]. Surprise - most of modern text-based games don't do that.

    Text-based game that understands 'hello' but can't understand 'hello, how are you?' fails one of the main tasks of text-based game - text processing. It was 'okay' 30 years ago. But now you need something more to impress players.

I didn't want a list of tutorials here again but, well, I feel I still need a list of resources for complete newcomers in gamedev world:

1.) Good python tutorial. Contains code for a text-based game with rooms and items.
2.) Question on stackexchange with example of game code with tons of if-clauses and tips for the ways of improving it.
3.) C++ article about writing of text adventure game from scratch.

    If you choose the way I described above - you can even say someday 'Hey, guys, I don't want text-only game anymore. I want to add awesome graphics and sound' - and you will do this, and the code you written for your text-based game will not be useless.

    That's all for now.

    Do you feel comfortable playing text adventure games with 'traditional' design? Maybe you faced problems with processing of different types of inputs with the same meaning in other types of games?

2 comments: