Game Development Reference
In-Depth Information
The
text
,
speak
, and
select
variables will all be used to hold the current complete
string of text, and other objects will change these variables directly to alter what is
being spoken. The
text_previous
variable will be used to keep a record of the previous
string of text so we can tell when another object has altered one of these variables (as it
will no longer be the same as
text_previous
).
The
displayed_words
variable will be used to keep track of the number of words
currently being displayed. Similarly, the
displayed_index
variable will record the
number of characters that make up those words. Based on these values, the
displayed_text
string will hold the actual string that needs to be displayed at any point
in time.
The
finished
variable will be used to signal when the entire speech text is being
displayed, and the
timeout
variable will signal that it has been displayed for a
reasonable amount of time. The
selected
variable will be set when the mouse pointer
is positioned on top of the text, and the
selectable
variable determines whether the
words should be highlighted when they do. The final line of the
Create
event sets
Alarm 0
to go off after the number of steps defined by
word_delay
.
2.
Now add the
Alarm, Alarm0
event and include an
Execute Code
action containing the
following code. This simply adds one to the number of words being displayed and then
sets the alarm to go off again in another three steps. It provides the timing mechanism
for displaying text word by word.
{
displayed_words += 1;
alarm[0] = word_delay;
}
3.
Next add a
Step,
End Step
event and include an
Execute Code
action containing the
following code:
1:
{
2:
displayed_index = string_length_words( text, displayed_words );
3:
displayed_text = string_copy( text, 0, displayed_index );
4:
5:
if( displayed_index == string_length( text ) && finished == false )
6:
{
7:
finished = true;
8:
alarm[1] = 300;
9:
}
10:
}
This code begins by using our
string_length_words
script to get the number of
characters that make up
displayed_words
within the text string. It then copies this
string to the
displayed_text
variable in line 3 ready to be drawn in the
Draw
event.
Line 5 checks to see if we're displaying the entire string, but haven't already set the
finished
variable to
true
. If this is the case, then the
finished
variable is set to
true
and
Alarm1
is set to 10 seconds.
4.
Now add that
Alarm, Alarm1
event and include an
Execute Code
action containing the
following code to set the
timeout
variable after the 10 seconds have expired.
{
timeout = true;
}
Search WWH ::
Custom Search