Game Development Reference
In-Depth Information
Punctuating Text
So the objects we've given you already handle the big picture as far as the dialogue is concerned,
and these will change for each new character and conversation. However, we still need to
implement the functionality that displays the text on the screen. The convention for spoken text
in games is for it to appear one word at a time, but this is not straightforward to achieve.
Nonetheless, if you understand how it works, then you should be able to incorporate a similar
system into your own games, so it's worth going through step by step.
The Word Script
There is one main script that lies at the heart of making the text appear one word at a time. This
script will take a string and a number of words as arguments, and return the length (in characters)
of that number of words from the start of the sentence. We'll call our new script
string_length_words , as it's similar to the Game Maker string_length function that returns the
length of a complete string (in characters).
Once we know how many characters to display for a given number of words, we can then use
Game Maker's string_copy function to create a new version of our original string that just
contains the number of words required. Keep performing this process with an increasing value
for the number of words and you can create spoken text that appears one word at a time.
Creating the string_length_words Script
1. Working from dialogue1.gmk , create a new script called string_length_words and
type the following code:
1: {
2: var str, words, count, index, length;
3:
4: str = argument0;
5: words = argument1;
6:
7: index = 0;
8: count = 0;
9:
10: length = string_length( str );
11:
12: while( count < words && index < length )
13: {
14: index +=1;
15:
16: if( string_char_at( str, index ) == " " )
17: count += 1;
18: }
19:
20: return index;
21: }
 
Search WWH ::




Custom Search