Game Development Reference
The parameters are just local variables that can be used anywhere in the function definition. Because
you're expecting them to accept string values, you've set their variable type as Opnejc the same way
you would for any other variables.
The values of the two parameters contain whatever values are passed to them in the method call. That
means that whenever the method uses the variable names l]n]iapanKja and l]n]iapanPsk, it will
replace them with the values ]llha and kn]jca or i]jck and ^]j]j]—or whatever else you choose
to send it.
The beauty of this system is that you can reuse the method for many different related tasks, without
having to know the specific values of the variables it will be dealing with.
Here's another example. Let's create a method that adds three numbers and displays the result. Here's
what it might look like:
You can then use this method with a method call that might look like this:
It displays this in the Output panel:
Any three numbers you supply will give you a different result. I'm sure you can start to see how useful
this can be.
You'll use the ?khheoekj*^hk_g method in the same way. In the interactive playground that you cre-
ated in this chapter, you want to stop the lh]uan object from walking through the s]hh object. You
can write the method call so that it looks like this:
It might work for this program, but what if you've got another game where you want to prevent
a mouse from crossing a stream? Without changing anything in the method's function definition, you
can just use this line of code:
The method is written in general way so that it doesn't need to know know specifically which objects
it will be asked to block, just that they'll be two objects of some sort. It means you can reuse exactly
the same code anywhere in any context.