PDA

View Full Version : NPCServer updates


Admins
05-18-2007, 09:28 PM
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"


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:


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, 09:31 PM
Stuff

Very cool!

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

Matt
05-18-2007, 09:36 PM
Very nice updates, Stefan. :)

killerogue
05-18-2007, 09: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, 10:21 PM
Nice Stefan. :)

Deadly_Killer
05-18-2007, 10:25 PM
/scripthelp text: print help for a server side function
/scriptscan weapons/npcs/classes/levels/all text: scan scripts

Very cool!

JkWhoSaysNi
05-18-2007, 10: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, 11:58 PM
Cool...

JkWhoSaysNi
05-19-2007, 12:08 AM
now i remember! I wanted some OO functionality without using classes.
If I did this:


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

function onCreated() {
x = 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, 02:46 AM
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, 03:21 AM
So what about returning information through this, doesn't seem to work?

Rapidwolve
05-19-2007, 04:11 AM
So what about returning information through this, doesn't seem to work?

Not sure but something like this would probobly work:

function func()
return "Hi";

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

Twinny
05-19-2007, 06:15 AM
Aww...printf() in loops problem wasn't fixed :cry:.

MegaMasterX90875
05-19-2007, 06:25 AM
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"


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:


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, 06:27 AM
Not sure but something like this would probobly work:

function func()
return "Hi";

function onCreated()
{
t = new TStaticVar();
t = 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.


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.


function onCreated()
{
this.newObj = function() {
return (1 + 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, 12:11 PM
You can also do this, but keep care to add a semicolon behind the function declaration:


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, 01:13 AM
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.

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, 04:28 AM
I can't seem to get function objects to work as expected:


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:
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, 04:39 AM
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, 06: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, 06:41 AM
if ( func( "blah" ) )

vs.

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

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

>_>

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

VS

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

is more like it :p

killerogue
05-20-2007, 06:43 AM
Point is, this limits the amount of functions you catch and call.

Chompy
05-20-2007, 06:47 AM
Point is, this limits the amount of functions you catch and call.

true

Rapidwolve
05-20-2007, 07: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, 07: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, 10:57 AM
if ( func( "blah" ) )

vs.

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

Any other uses?
That doesn't make any sense to me.
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, 03:00 PM
>_>

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

VS

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, 03:32 PM
Is there a point to this?

Yep

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.

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

Inverness
05-22-2007, 12:34 AM
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, 02:06 AM
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, 02: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, 09: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, 12:45 PM
Fun stuff!
Good job :)

Admins
05-28-2007, 12:20 PM
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
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):

//#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
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
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.

//#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



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

Tolnaftate2004
02-27-2008, 10:37 AM
strange, no idea but would ths work



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


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