Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
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
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 05:02 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.