Game Development Reference
In-Depth Information
When the game starts, the cqaooaoNai]ejejc variable is initialized to -,. On the first click of the guess
button, this directive is run:
It subtracts 1, making its new value 5. On the next click, the very same directive runs again, and 1 is
subtracted for the second time, leaving it with a value of 4. One will be subtracted every time the but-
ton is clicked for the rest of the game.
The cqaooaoI]`a variable does the same thing, but instead uses the double-plus sign to add 1 to its
value. When you test the game, you can clearly see how this is working by the way the values update
in the output text field.
Tying up strings
You created another new variable in the program called c]iaOp]pqo. You declared this variable as
a Opnejc, which means that it will be used to store text. The first time it makes its appearance is in
this directive:
c]iaOp]pqo9CqaooaoNai]ejejc6'cqaooaoNai]ejejc' ±
For the uninitiated, this is a potentially terrifying segment of code. What on earth does it do?
The first time you make a guess in the game, you'll see the following text on the second line of the
output text field:
This text has to come from somewhere, and it's the preceding directive that's responsible for putting
it all together.
Think about it carefully: what are the values of the cqaooaoNai]ejejc and cqaooaoI]`a variables the
first time you click the Guess button? (They're 5 and -.)
Okay then, let's imagine that you replace the variable names you used in the directive with the actual
numbers they represent: 9 and 1 . It will look something like this:
Make sense, right? Great, now let's pretend that the plus signs have disappeared and everything is
inside a single set of quotes:
Aha! Can you see how it's all fitting together now? That's exactly the text that is displayed in the out-
put text field. Figure 5-15 shows how the entire line of text is interpreted, from the initial directive to
being displayed in the output text field.
Search Nedrilad ::

Custom Search