Game Development Reference
In-Depth Information
Creating method arguments and parameters
The simple `eolh]uPatp method works pretty well, but there's a problem with it. The text it displays
always stays the same. Wouldn't it be nice if you could write the method so that you could supply it
with new text to display every time it's called?
Of course it would be! Here's what the new method call might look like:
`eolh]uPatp$Ukq_]jsnepa]jupatpukqhegadana%7
The method call now includes an argument. The argument is the text that you want to display.
To display this text, you need to rewrite the function definition with a parameter, which is a variable
that is used to store the new information. That variable can then be used anywhere in the function
definition to access the information that was sent by the method call.
It's really easy to do. Have a look:
bqj_pekj`eolh]uPatp$patpUkqS]jpPk@eolh]u6Opnejc%6rke`
w
pn]_a$patpUkqS]jpPk@eolh]u%7
y
If you use this method in a program, the Output panel displays You can write any text you like here!
The beauty of this system is that you need to write the function definition only once. You can change
the text that the method displays just by changing the text in the method call's argument. For example,
you can use any of these method calls, and the display in the Output panel will change to match it:
`eolh]uPatp$=hhpdeopatp%7
`eolh]uPatp$_]j_d]jcasdajaranukqs]jpeppk%7
`eolh]uPatp$sepdkqp_d]jcejcpdabqj_pekj`abejepekj%7
This makes the method very versatile. Here's the key to understanding it:
1. The text in the method call's argument is sent to the function definition.
2. The function definition stores that text in a variable. The name of the variable that it stores it in
is supplied in the parameter. In this case, the name of the variable is patpUkqS]jpPk@eolh]u.
 
Search Nedrilad ::




Custom Search