# How do you handle NPC Text in your games?

This topic is 5069 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was curious as to how people handled NPC text/speach in their games. ie; How it's tored and how it's accessed. Currently I have mine stored in the source code, which isn't the brightest of ideas. What I do is have a database that stores TextLists, and during load up I create them: tl_t* pText = new TextList(id, size); pText->TextVect.push_back("character text"); .. so on. In the map editor I specify the TextList ID to use for each NPC, and when the main character is near, he says something random from his TextList. So basically I'm looking for new ideas on how to handle NPC text. :) Thanks for your time.

##### Share on other sites
well, usually, it's a lookup table of text entries. We use an Excel spreadsheet, so we can localise and put the text into categories (e.g. category = page number) and do other fancy stuff. First column is the name of the enum text, other columns are the text in english, spanish, french, ... Text is also stored as unicode for asian localisation. That gets exported into packed files for the game. At export, Text IDs (stored in the first column) are also converted into a large .h file for lookup text IDs in the code.

As far as organising the dialog and logic between NPCs, that's another story, much more complicated.

EDIT : For you, there is nothing wrong into creating a table of text entries hardcoded in a CPP/h file. When we started the game, at the first stage of development, that's what we used. Then when things were getting serious, localisation tools.

##### Share on other sites
Hmm.. this is the second time I've heard of Excel being used to export game data.
Are there any tutorials on how they're used and how the info can be read? I'm also curious about creating .h files with the info (enum values like you mentioned would be awsome). I'm sure it's not too difficult, but I don't know what format Excel saves things in.

What sounds great about this idea is that I won't have to change the way my map is saved at all, I can still stick with the IDs I currently have.

##### Share on other sites
Excel (or even just MS Works Spreadsheet) can export to a variety of formats of which possibly the most useful would be the 'Text & Tabs' or 'Text & commas'. You could use the other formats (binary?) but would have to find a description of it to parse. Also I would expect excel to be able to export to xml.

If you use text, then you'll get a text file where each element is seperated by a Tab or comma, and each line represents a row. This is fairly simple to parse at runtime, or as a pre-process to store in a more useful format. You could even have a program that writes the data into you enumerated .h file.

##### Share on other sites
For you guys say you use Excel, you should look into XML...You can easily mold to suit your every need in this manner. You could do something like the following (though, you'd obviously change it based upon your needs). In this example, I assume that clicking any of the buttons in a text window will close that window (though it may potentially open another text window, as you will see below). Use your imagination...

<?xml version="1.0"?><conversations>    <messageList ownerNpc="1">        <message id="1">            <text>This is a simple message.  I only have one option!</text>            <buttonList>                <button text="Close"/>            </buttonList>        </message>    </messageList>    <messageList ownerNpc="2">        <message id="1">            <text>This is a bit more complex message.  I have two options!  Neither of them do anything though.</text>            <buttonList>                <button text="Okay"/>                <button text="Cancel"/>            </buttonList>        </message>    </messageList>    <messageList ownerNpc="3">        <message id="1">            <text>I have two messages.  One of them leads to another message I have to tell you.  Would you like to read it?</text>            <buttonList>                <button text="Yes, please!" nextMessage="2"/>                <button text="No, thanks"/>            </buttonList>        </message>        <message id="2">            <text>This is my second message!  You're reading it because you asked to!  Would you like to see what I said a moment ago?</text>            <buttonList>                <button text="Yes, please!" nextMessage="1"/>                <button text="No, thanks"/>            </buttonList>        </message>    </messageList>    <messageList ownerNpc="4">        <message id="1">            <text>Hello, traveler!  Welcome to our wonderful town!</text>            <buttonList>                <button text="Close"/>            </buttonList>        </message>        <message id="2">            <text>Traveler, you look lost!  Is there something I can help you with?</text>            <buttonList>                <button text="Yes" nextMessage="3"/>                <button text="No"/>            </buttonList>        </message>        <message id="3">            <text>What do you need help with?</text>            <buttonList>                <button text="Where is the inn?" nextMessage="4"/>                <button text="Where is the armory?" nextMessage="5"/>                <button text="Are you for hire?" nextMessage="6"/>                <button text="Nevermind"/>            </buttonList>        </message>        <message id="4">            <text>The inn can be found to the north-east of town.  Just follow the path we're on!  Is there anything else you need help with?</text>            <buttonList>                <button text="Yes" nextMessage="3"/>                <button text="No"/>            </buttonList>        </message>        <message id="5">            <text>The armory is right behind me!  Is there anything else you need help with?</text>            <buttonList>                <button text="Yes" nextMessage="3"/>                <button text="No"/>            </buttonList>        </message>        <message id="6">            <text>Sorry, I'm not daring like all you crazy adventurers!  But I hear there have been several adventurers like yourself in and out of town.  Is there anything else you need help with?</text>            <buttonList>                <button text="Yes" nextMessage="3"/>                <button text="No"/>            </buttonList>        </message>    </messageList></conversations>

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 9
• 9
• 15
• 14
• ### Forum Statistics

• Total Topics
634070
• Total Posts
3015333
×