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

Skyld 05-19-2007 11:11 AM

Quote:

Originally Posted by Stefan (Post 1309177)
You can also do this, but keep care to add a semicolon behind the function declaration:

PHP Code:

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


Function prototypes! One of the best additions yet by far.

Wondering if it would be possible to have this.foo = public function () also, or something similar. Defining functions using this method in a TStaticVar results in a function inaccessible error in RC. Currently it is a bit of a pain to have to define a public function and copy it, if the functions you are defining are different for each object.

Admins 05-20-2007 12:13 AM

Quote:

Originally Posted by Twinny (Post 1309396)
Aww...printf() in loops problem wasn't fixed :cry:.

Yes sorry, just checked again and found the problem, so it will be fixed with the next update.

Quote:

Originally Posted by Skyld (Post 1309428)
Function prototypes! One of the best additions yet by far.
Wondering if it would be possible to have this.foo = public function () also, or something similar. Defining functions using this method in a TStaticVar results in a function inaccessible error in RC. Currently it is a bit of a pain to have to define a public function and copy it, if the functions you are defining are different for each object.

May be they should be public by default?

JkWhoSaysNi 05-20-2007 03:28 AM

I can't seem to get function objects to work as expected:

PHP Code:

public function sampleFunction() {
 return 
this.test this.test2;
}

public function 
someClass() {
obj2 = new TStaticVar();
obj2.test 0;
obj2.test2 0;
obj2.sampleFunction this.sampleFunction;
return 
obj2;
}

function 
onCreated() {
  
newClass someClass();
  
newClass.test 1;
  
newClass.test2 2;
  echo(
newClass.sampleFunction()); //should echo 3?


Even cutting it down:
PHP Code:

 obj2 = new TStaticVar();
  
obj2.test 3;
  
obj2.test2 4;
  
obj2.sampleFunction this.sampleFunction;

  echo(
obj2.sampleFunction()); 

These give errors in RC: GraalScript: Function unknown_object.sampleFunction not accessible at line 12 in script of class_test


Do function objects only work on this. variables?

killerogue 05-20-2007 03:39 AM

Quote:

Originally Posted by JkWhoSaysNi (Post 1309760)
stuff

Well, to be honest I didn't know you could even return objects?

But so far all I've witnessed object functions to be usable with is this. prefix. I tried it with temp and it didn't work for the most part, I'll make sure to test that out again, but I think it should work in general tho.

E: Definitely only useable with this. prefix. The question is if this is so limited, can we get some more effective or in-depth uses of pointer functions. At this time I don't really see the use.

cbk1994 05-20-2007 05:37 AM

if ( func( "blah" ) )

vs.

this.funct = func();
if ( this.funct( "blah" ) )

Any other uses?
That doesn't make any sense to me.

Chompy 05-20-2007 05:41 AM

Quote:

Originally Posted by cbkbud (Post 1309794)
if ( func( "blah" ) )

vs.

this.funct = func();
if ( this.funct( "blah" ) )

Any other uses?
That doesn't make any sense to me.

>_>
PHP Code:

function onCreated()
{
  if (
func("blah")) {
    
stuff();
  }
}
function 
func(foo) {
  return 
true;


VS
PHP Code:

function onCreated()
{
  
this.funct = function() {
    return 
true;
  };
  if (
this.funct("blah")) {
    
stuff();
  }


is more like it :p

killerogue 05-20-2007 05:43 AM

Point is, this limits the amount of functions you catch and call.

Chompy 05-20-2007 05:47 AM

Quote:

Originally Posted by killerogue (Post 1309797)
Point is, this limits the amount of functions you catch and call.

true

Rapidwolve 05-20-2007 06:00 AM

I honestly think this is useless and is just causing confusion. I get it, but at the same time it still confuses me

Novo 05-20-2007 06:15 AM

I find that the most practical thing about this function thing if for sorting... Basically, passing the function the depicts which value is greater.

Skyld 05-20-2007 09:57 AM

Quote:

Originally Posted by cbkbud (Post 1309794)
if ( func( "blah" ) )

vs.

this.funct = func();
if ( this.funct( "blah" ) )

Any other uses?
That doesn't make any sense to me.

Quote:

Originally Posted by Rapidwolve (Post 1309801)
I honestly think this is useless and is just causing confusion. I get it, but at the same time it still confuses me

If you do not understand the use of them, I suggest that you learn JavaScript and use them there.

They are very useful for controlling functions at execution time, and they are a lot more organised in event-driven system.

cbk1994 05-20-2007 02:00 PM

Quote:

Originally Posted by Chompy (Post 1309796)
>_>
PHP Code:

function onCreated()
{
  if (
func("blah")) {
    
stuff();
  }
}
function 
func(foo) {
  return 
true;


VS
PHP Code:

function onCreated()
{
  
this.funct = function() {
    return 
true;
  };
  if (
this.funct("blah")) {
    
stuff();
  }


is more like it :p

Is there a point to this?

Chompy 05-20-2007 02:32 PM

Quote:

Originally Posted by cbkbud (Post 1309853)
Is there a point to this?

Yep

Quote:

Originally Posted by Skyld (Post 1309831)
If you do not understand the use of them, I suggest that you learn JavaScript and use them there.

They are very useful for controlling functions at execution time, and they are a lot more organised in event-driven system.

Quote:

Originally Posted by killerogue (Post 1309797)
Point is, this limits the amount of functions you catch and call.


Inverness 05-21-2007 11:34 PM

Quote:

Originally Posted by killerogue (Post 1309763)
Well, to be honest I didn't know you could even return objects?

A TGraalVar that is an "Object" exists as a reference to the object so no matter where the variable is it will always point to a specific object. And yes, you can return object references.

It is something I used in my mud system, you construct all mud objects in a single array and return the object reference with the function. Having a master list prevents the object from being destroyed because of lack of references. Though I don't know what Graal does when all references are removed, I expect it similar to Java.

Twinny 05-22-2007 01:06 AM

Quote:

Originally Posted by Inverness (Post 1310336)
Though I don't know what Graal does when all references are removed, I expect it similar to Java.

Currently destroying a child staticvar within a parent staticvar leaves a pointer in the parent to the child. Basically it points to 0's. Highly annoying for debugging ^^. Hopefully it will be fixed soon.

Inverness 05-22-2007 01:46 AM

I already know points are left behind but I meant the object itself. If it wasn't destroyed on loss of references it could still function.

Twinny 05-22-2007 08:15 AM

Hmm...i doubt gscript has a garbage collector. Make a random global TStaticVar(), remove the code that made it and check up on it every now and then ^^.

zokemon 05-22-2007 11:45 AM

Fun stuff!
Good job :)

Admins 05-28-2007 11:20 AM

Quote:

Originally Posted by Twinny (Post 1310554)
Hmm...i doubt gscript has a garbage collector. Make a random global TStaticVar(), remove the code that made it and check up on it every now and then ^^.

There is, it's quite accurate, checking recursive links.

About the "not accessible" error: I have fixed it, will upload new npcservers soon.

About npc rights problems: The problem is that people write their account name wrong (wrong case), so the npcserver is not accepting it; to fix it write it correctly e.g. Shadow87 instead of shadow87, I will also upload new npcservers soon.

Twinny 02-26-2008 12:53 PM

Reviving thread here but are variable functions available on the client yet? I tried to make one but it didn't work :cry:

Tolnaftate2004 02-26-2008 06:08 PM

Quote:

Originally Posted by Twinny (Post 1376644)
Reviving thread here but are variable functions available on the client yet? I tried to make one but it didn't work :cry:

They work (at least in simple cases):

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
this.test_func = function () {
    echo(
"I win!");
  };

  
this.test_func();


I've seen the functionality break down within with() blocks.

Inverness 02-27-2008 01:07 AM

Quote:

Originally Posted by Tolnaftate2004 (Post 1376660)
I've seen the functionality break down within with() blocks.

If you return in a with() block crazy stuff happens.

Tolnaftate2004 02-27-2008 04:10 AM

Quote:

Originally Posted by Inverness (Post 1376713)
If you return in a with() block crazy stuff happens.

This is true, but I meant that dynamic functions are treated more like inline functions.

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
temp.var = new TStaticVar();
  
with (temp.var) {
    
this.test_func = function () {
      echo(
"I win!");
    };
  }

  
temp.var.test_func(); // Doesn't work



xAndrewx 02-27-2008 10:07 AM

strange, no idea but would ths work


PHP Code:

temp.var.test_func = function() 
{
  echo(
"I Win!");



Tolnaftate2004 02-27-2008 10:37 AM

Quote:

Originally Posted by xAndrewx (Post 1376764)
strange, no idea but would ths work


PHP Code:

temp.var.test_func = function() 
{
  echo(
"I Win!");



Yes, granted they are called & defined in the same scope (as far as I can tell).


All times are GMT +2. The time now is 01:26 AM.

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