View Single Post
  #9  
Old 05-07-2011, 04:36 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Devil_Lord2 View Post
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(5283);
  echo(
"mean: " temp.mean);
}

function 
getMean(temp.n1temp.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.
__________________
Reply With Quote