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)

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.


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

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