Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Announcements (https://forums.graalonline.com/forums/forumdisplay.php?f=240)
-   -   NPCServer updates (https://forums.graalonline.com/forums/showthread.php?t=74042)

Admins 05-18-2007 08:28 PM

NPCServer updates
 
Today the npcservers have been updated. Here some of the updates:

- /style works again
- improved /scripthelp which also lists object types that match
- fixed int(random(lowerlimit, upperlimit)) which sometimes reached upperlimit (when the random number was too close to the upperlimit it was rounding to upperlimit)
- scripts can now access image files (png, gif, jpeg) and also files inside the levels folder if the npcserver has the rights for that
- if you call a function of another object which is non-public, then it will display that the function is not accessible, instead of saying that the function doesn't exist
- graal script now supports function objects: this will print "param: 123"

PHP Code:

function onCreated() {
  
this.func this.func1;
  
this.func(123);
}
function 
func1(param) {
  echo(
"param: " param);


You can also do this, but keep care to add a semicolon behind the function declaration:

PHP Code:

this.func = function() {
  echo(
"nameless function");
}; 

This is only working on serverside, it will work on clientside with the next Graal version.
There is a protection against unsetting functions, since often scripts use the same name for functions and variables. If the variable is not linking to a function but the script contains a function with that name, then it will use the function defined in the script instead. You can however link to another function.

godofwarares 05-18-2007 08:31 PM

Quote:

Originally Posted by Stefan (Post 1309177)
Stuff

Very cool!

Edit: But what is the point of doing function objects? o.O

Matt 05-18-2007 08:36 PM

Very nice updates, Stefan. :)

killerogue 05-18-2007 08:47 PM

Function objects!

What do they do? Sounds like fun.

Edit: The first one I understand as being able to assign a function name to a variable. Being able to add params to the functionname by calling the variable as the function and receiving it using the assigned function name to the variable.

Ah, tested out the later, the beauty of it is you don't need to actually receive the function. Now that is sexy.

Edit 2: There's only a few problems I'm having, like not being able to return information and work with objects inside the "embedded functions".

xXziroXx 05-18-2007 09:21 PM

Nice Stefan. :)

Deadly_Killer 05-18-2007 09:25 PM

Quote:

/scripthelp text: print help for a server side function
/scriptscan weapons/npcs/classes/levels/all text: scan scripts
Very cool!

JkWhoSaysNi 05-18-2007 09:50 PM

Very nice! I wanted function pointers for something a while ago... but now I can't remember what it was :P

Switch 05-18-2007 10:58 PM

Cool...

JkWhoSaysNi 05-18-2007 11:08 PM

now i remember! I wanted some OO functionality without using classes.
If I did this:

PHP Code:

public function increment() {
this.count++;
}

function 
onCreated() {
 
= new TStaticVar;
 
x.increment this.increment;
 
x.count 1;
 
x.increment();  //x.count = 2?


Will x.count get incremented when x.increment() is called or will count get incremented in the script which created x?

Admins 05-19-2007 01:46 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1309235)
Will x.count get incremented when x.increment() is called or will count get incremented in the script which created x?

x.count will be incremented

killerogue 05-19-2007 02:21 AM

So what about returning information through this, doesn't seem to work?

Rapidwolve 05-19-2007 03:11 AM

Quote:

Originally Posted by killerogue (Post 1309301)
So what about returning information through this, doesn't seem to work?

Not sure but something like this would probobly work:
PHP Code:

function func()
  return 
"Hi";

function 
onCreated()
{
= new TStaticVar();
this.func;
echo(
t);



Twinny 05-19-2007 05:15 AM

Aww...printf() in loops problem wasn't fixed :cry:.

MegaMasterX90875 05-19-2007 05:25 AM

Quote:

Originally Posted by Stefan (Post 1309177)
Today the npcservers have been updated. Here some of the updates:

- /style works again
- improved /scripthelp which also lists object types that match
- fixed int(random(lowerlimit, upperlimit)) which sometimes reached upperlimit (when the random number was too close to the upperlimit it was rounding to upperlimit)
- scripts can now access image files (png, gif, jpeg) and also files inside the levels folder if the npcserver has the rights for that
- if you call a function of another object which is non-public, then it will display that the function is not accessible, instead of saying that the function doesn't exist
- graal script now supports function objects: this will print "param: 123"

PHP Code:

function onCreated() {
  
this.func this.func1;
  
this.func(123);
}
function 
func1(param) {
  echo(
"param: " param);


You can also do this, but keep care to add a semicolon behind the function declaration:

PHP Code:

this.func = function() {
  echo(
"nameless function");
}; 

This is only working on serverside, it will work on clientside with the next Graal version.
There is a protection against unsetting functions, since often scripts use the same name for functions and variables. If the variable is not linking to a function but the script contains a function with that name, then it will use the function defined in the script instead. You can however link to another function.

Yet another moment where GS2 has unlimited possibilities opened. Thanks Stefan, WHEEEEEEEE

killerogue 05-19-2007 05:27 AM

Quote:

Originally Posted by Rapidwolve (Post 1309326)
Not sure but something like this would probobly work:
PHP Code:

function func()
  return 
"Hi";

function 
onCreated()
{
= new TStaticVar();
this.func;
echo(
t);



Yeah, RW that returned func. So, I'm not sure. This seems to contain a few bugs as it were because it's new. But as far as returning information I had been doing things like.

PHP Code:

function onCreated()
{
  
this.newObj = function() {
    echo(
"stuff");
  };
 
  
this.newObj();


And I have been trying to, for lack of a better word, reverse engineer that into something like.

PHP Code:

function onCreated()
{
  
this.newObj = function() {
    return (
2);
  };
 
  echo(
this.newObj());


And lol, whaddya know...it works that way, this has to be experiemented on a bit. As it returned the right thing just now. =o


All times are GMT +2. The time now is 09:44 AM.

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