Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   function question (https://forums.graalonline.com/forums/showthread.php?t=29379)

nyghtGT 05-17-2002 11:29 PM

function question
 
Does stuff like this work?
NPC Code:

NPC Code:

operator(1,7);

function operator(a,b) {
message a;
sleep 1.75;
message b;
}




I've tried it and nothing happens but if its messed up somewhere please correct me.

GrowlZ1010 05-18-2002 12:24 AM

It won't work, no. Graal has no support for function parameters at the moment.

Bhala 05-18-2002 09:04 AM

All a function is in graal is code replacement.... like saying

if(true){
dothis();
}
function dothis(){
message done!;
}


is the same as

if(true){
message done!;
}

Falcor 05-18-2002 10:43 PM

Fuctions are more of a branch.

initial code branches to the fuction and then comes back. Fuctions branch to other fuctions. etc etc. Think of it as sort of a Tree (like the side bar in Explorer for windows My Computer stuff) rather than standard replacement.

Bhala 05-18-2002 10:53 PM

Quote:

Originally posted by Kaimetsu
:-/

That's a misleading analogy. The internal working is nothing like that.

A true function works nothing like that but in Graal thats all they do.

Falcor 05-18-2002 11:03 PM

Yes bhala, in graal thats exactly what it does, but it doesnt acually work like that =\.

Bhala 05-18-2002 11:08 PM

Whats the point of explaning the internal workings when all he needs to know is what it does?

Falcor 05-18-2002 11:31 PM

Maybe to not rot out his mind if he wants to try other, more practical forms of programing like C++ ;)

Bhala 05-19-2002 02:14 AM

lol true...

nyghtGT 05-19-2002 02:24 AM

Quote:

Originally posted by Kaimetsu
:-/

That's a misleading analogy. The internal working is nothing like that.

function parameters are suppose to be in the new scripting engine correct?

nyghtGT 05-19-2002 12:53 PM

Quote:

Originally posted by Kaimetsu
Don't hold your breath for it.
*thinks of 2k2*

I know better;)

Saga2001 05-20-2002 11:03 PM

Well about the new engine, a few weeks back Stefan said about a year...
Which sucks, however functions are very useful with classes and arrays.
I don't understand when people have a function that they only call once, because one of the points of functions is things you use more than once, like this:
NPC Code:

if (created || initialized) {
// Attributes restarted.
setarray this.stats, 100;
for (i=0; i<100; i++) setStatus();
}
function setStatus() {
this.stats[i] = random(-1, 1);
// do a lot of code so that calling a function isn't a waste of time
// they really are style things, it makes your code look more pretty.
return;
}



Now since this is a Graal function and Gscript, there is no real reason for the return, however I have always thought it should help with execution so that the function knows it has returned so it doesn't have to keep looking for code. In something more like PHP you may have code like this:
PHP Code:

function sql_conn($database) {
 
$user "user";
 
$pass "pass";
 
$host "localhost";
$connection mysql_connect($host$user$pass);
 if (
$connection) {
  
mysql_select_db($database); // See here it used the variable passed by the function.
  
return $connection;
 } else return 
0// Returning 0 is like returning saying the function didn't work.
}
if (
count($HTTP_POST_VARS)>0) {
 if (
$conn sql_conn("database_a"))
  echo 
"Wassup? mySQL is connected with connection id: $conn";
 else
  echo 
"Sadly mySQL didn't connect, it probably doesn't appreciate your stench.";


See fun fun fun functions. Well Hope that explaination helped, if thats even what you were asking, all you really need to do to pass "params" in fuctions is use callnpc, or you could just use this.vars since Graal has a global scope.


All times are GMT +2. The time now is 08:45 PM.

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