Quote:
Originally Posted by Devil_Lord2
 I don't get it...
|
Imagine you're using a default function like
degtorad(degrees). You use it like this:
PHP Code:
temp.radians = degtorad(180);
echo(temp.radians);
The function
degtorad returns the degrees given as a radian. You then have to assign it to a variable to use it elsewhere in the script. It works the same way when you create your own functions:
PHP Code:
function onCreated() {
temp.playerCount = this.getPlayerCount();
}
function getPlayerCount() {
temp.count = allplayers.size();
return temp.count; // this statement controls what the function returns
}
Another example of a function:
PHP Code:
function onCreated() {
temp.mean = this.getMean(52, 83);
echo("mean: " @ temp.mean);
}
function getMean(temp.n1, temp.n2) {
return ((temp.n1 + temp.n2) / 2);
}
You see here how you don't even have to assign the return value to a variable. Essentially, the interpreter reads that line of code, sees that it needs to use the
getMean function, evaluates that function and places the return value in place of that statement.
If it helps, think of the function as a function in math.