#70562 - Sasami-chan - Tue Feb 07, 2006 9:50 am
Call me an idiot. know how to print text onto the screen, but I can't seem to figure out a way to efficiently store dialog text. How are dialog text stored in commercial games? Please help! A pointer to some kind of tutorial is deeply appreciated. I did a search on the forum before posting, but I couldn't find anything. Thanks! :)
#70563 - sgeos - Tue Feb 07, 2006 10:29 am
You'll want to write custom tools to convert your messages to a format like this: Code: |
#include <stdio.h>
const char msg_000[] = "";
const char msg_001[] = "Hello world!";
const char msg_002[] = "Do you like cheese?";
const char msg_003[] = "Yes";
const char msg_004[] = "No";
const char const *const msg[] =
{
msg_000,
msg_001,
msg_002,
msg_003,
msg_004,
};
const int msg_cnt = sizeof(msg) / sizeof(const char *const);
int main(void)
{
int i;
for (i = 0; i < msg_cnt; i++)
printf("%s\n", msg[i]);
return 0;
} |
-Brendan
#70592 - naleksiev - Tue Feb 07, 2006 3:57 pm
I'm a big fan of C# so all the tools that I create are using C#. For storing the texts in my game I use XML file that describe my texts. Than I have a tool that transform this texts in better format for using it with GBA/C++.
For example my xml is
Code: |
<texts>
<text id="HELLO" value="Hello World!"/>
<text id="CHEESE" value="Do you like cheese?"/>
<text id="YES" value="Yes"/>
<text id="NO" value="No"/>
</texts> |
The tool that I create for my game read this XML and generate 2 files. One is with defines:
texts.h
Code: |
#define STR_HELLO 0
#define STR_CHEESE 1
#define STR_YES 2
#define STR_NO 3 |
that contain in the begining offset of every text in 2 bytes so in this case I will have 8 bytes with the offsets of the strings. Than I have the strings and after every string I have 0 byte. So you can directly use it with char*.
I have one small function char* getString(u16 id); that I use like getString(STR_HELLO);
There are some advantages to use this than hard coded string.
- You can verry easely localize your game.
- If you want to rearange something in your strings like if you want to add one more greating message after Hello World (just to group the texts in more butiful order) you don't need to change enything in your code. just the texts.h file will be regenerated.
#70593 - ScottLininger - Tue Feb 07, 2006 4:16 pm
You can also store your dialog right inside your "scripting" code. Here's an example of code that gets compiled right into the game, where the main character speaks with his superior officer:
Code: |
if (getVar(currentAssignment) == NOASSIGNMENT) {
Speak(ALVIN,"Excuse me, are you the Chief? My name is Alvin. I just got here and I was told to report...");
WaitForButton();
Speak(WILLIAM,"I know who are, son, and yes, I'm the Chief, but everyone calls me William. We don't have time for formalities around here.");
WaitForButton();
Speak(WILLIAM,"We'll get you settled in, but first I have an assignment for you. My coffee mug is empty. I need a refill. Now.");
setVar(currentAssignment,GETCOFFEE);
} |
The "Speak" function would look something like this. It essentially just calls your text-writing function. The important part is the const char *myString. That's how you can pass a string to a function.
Code: |
void Speak(int characterID,const char *myString) {
DisplayDialogBox(characterID);
BlitString(str);
}
|
I agree with Brendan that eventually, you may want to write your own "map building" tool that allow you to attach dialog to characters and events within a simplified GUI, then have the tool output the code.
-Scott
#70658 - Miked0801 - Wed Feb 08, 2006 1:20 am
We Huffman compress our text and store a bit offset to each string. 33% compression or so after the lookup overhead.
#70664 - tepples - Wed Feb 08, 2006 1:45 am
Have you tried huffword? Huffword involves mapping each word (segment of alphanumeric characters) or nonword (segment of non-alphanumeric characters) to an integer symbol and then Huffman-compressing those.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.
#70850 - Sasami-chan - Thu Feb 09, 2006 2:16 am
These are exactly the kind of answers I was looking for.
Thank you all so much!
I kept trying to think of a way to store the script externally...
Can't wait to go home and try some things tonight! :)
Does there exist a tool for converting XML scripts into codes?
If not, I will definitely be writing one to save myself the hassle.
And if everything works out, I will try a Huffword implementation to reduce the file size.
ScottLininger, that's one wicked script. Very funny!
Thanks again, guys! :)
#71019 - tepples - Fri Feb 10, 2006 12:53 am
ScottLininger wrote: |
You can also store your dialog right inside your "scripting" code. Here's an example of code that gets compiled right into the game, where the main character speaks with his superior officer: |
Watch out. If you want to distribute your game outside the United States, the United Kingdom, Australia, and New Zealand, then you're not going to want to make things harder for your translators by putting human-language scripts into C code.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.