Game Development Reference
In-Depth Information
A small technical detail that you should be aware of is that the following directive
actually mixes Opnejc and qejp variables:
c]iaOp]pqo9CqaooaoNai]ejejc6'cqaooaoNai]ejejc' ±
(CqaooaoI]`a6'cqaooaoI]`a7
In the program, you declared the c]iaOp]pqo variable to be a Opnejc type. That
means it can't contain numbers, except in the form of numeric characters (which are
interpreted like letters or words). However, you declared both the cqaooaoNai]ejejc
and cqaooaoI]`a variables as qejp variables (which are interpreted as numbers). Both
of them are joined together with ordinary text and copied into the c]iaOp]pqo string
variable. Isn't the purpose of assigning variables types to prevent this sort of mixing
and matching between strings and numbers? How is this possible?
In fact, you can use number variables with strings by joining them together with plus
signs, but when you do this, AS3.0 converts the values of the number variables into
strings. The data type in the cqaooaoNai]ejejc and cqaooaoI]`a variables remains
unchanged as qejp, but the values they contain are converted into a string when
they're assigned to the c]iaOp]pqo Opnejc variable. This is very useful for exactly the
purpose you've put it to: to display text with numbers that are updated by the pro-
gram. It's such a common requirement in programs that AS3.0 does this type conver-
sion automatically. Thanks, Flash!
Now that you have the c]iaOp]pqo variable packed up and ready to go, you get lot of mileage out of
it in the eb+ahoa statement. The new bits of code are highlighted in bold:
eb$_qnnajpCqaoo:iuopanuJqi^an%
w
kqplqp*patp9Pd]p#opkkdecd*'Xj'c]iaOp]pqo7
y
ahoaeb$_qnnajpCqaoo8iuopanuJqi^an%
w
kqplqp*patp9Pd]p#opkkhks*'Xj'c]iaOp]pqo7
y
ahoa
w
kqplqp*patp9Ukqckpep7
y
You're using string concatenation to add the contents of the c]iaOp]pqo variable to the output text
field. But there's something here that you haven't seen before:
Xj
A backslash followed by the letter j is known as a newline character . The newline character forces
whatever text that comes after it onto a “new line.” That's why the game displays the game status
information just below the first bit of text.
 
Search Nedrilad ::




Custom Search