Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   Future Improvements (https://forums.graalonline.com/forums/forumdisplay.php?f=10)
-   -   Object functions... (https://forums.graalonline.com/forums/showthread.php?t=85511)

Tigairius 05-09-2009 11:38 PM

Object functions...
 
PHP Code:

//#CLIENTSIDE
function onCreated() {
  
obj.testfunct();
}

function 
obj.testfunct() {
  
player.chat "hi";


This does not work, you can't trigger your own functions onto other objects. However, you can do this and it works just fine:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  
obj.testfunc();
}

obj.testfunc = function() {
  
player.chat "hi";



So for further example:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  new 
GuiWindowControl("lalala") {
    
width height 50;
    
50;
    
profile GuiBlueWindowProfile;
  }
  
lalala.hi();
}

function 
lalala.hi() {
  
player.chat "hello";


This does not work. Neither does this:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  new 
GuiWindowControl("lalala") {
    
width height 50;
    
50;
    
profile GuiBlueWindowProfile;
    
thiso.catchEvent(this"hi""LALA123");
  }
  
lalala.hi();
}

function 
LALA123() {
  
player.chat "hello";


This doesn't work either:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  new 
GuiWindowControl("lalala") {
    
width height 50;
    
50;
    
profile GuiBlueWindowProfile;

    
this.hi = function() {
      
player.chat "hi";
    }
  }
  
lalala.hi();


However, this works fine:

PHP Code:

//#CLIENTSIDE
function onCreated() {
  new 
GuiWindowControl("lalala") {
    
width height 50;
    
50;
    
profile GuiBlueWindowProfile;
  }

  
lalala.hi = function() {
    
player.chat "hello";
  }

  
lalala.hi();


However, none of these problems occur serverside. So... yeah. :D

Crow 05-10-2009 09:29 AM

I've done some research on this topic before, and I have another quirky example of code:

PHP Code:

new GuiControl("toastControl") {
  
this.testFunc = public function() {
    echo(
"Hi there!");
  };
}

toastControl.testFunc(); 

The code works perfectly fine, but it throws a syntax error.

Chompy 05-10-2009 12:44 PM

Quote:

Originally Posted by Crow (Post 1490637)
I've done some research on this topic before, and I have another quirky example of code:

PHP Code:

new GuiControl("toastControl") {
  
this.testFunc = public function() {
    echo(
"Hi there!");
  };
}

toastControl.testFunc(); 

The code works perfectly fine, but it throws a syntax error.

That's just odd o.o

It works when using public function, but not without public..

PHP Code:

new GuiControl("toastControl") {
  
thiso.toast this;
}
this.toast.testFunc = function() {
  echo(
"Hi there!");
};
this.toast.testFunc(); 

The above works, but the other 'object functions' issues should be fixed :(

LoneAngelIbesu 05-10-2009 04:33 PM

Can't you just join the object to a class?

Class guifunctions:
PHP Code:

//#CLIENTSIDE
function changetext(newtext) {
  
this.text temp.newtext;
  
player.chat "Changed text to " temp.newtext;


Weapon GUI:
PHP Code:

//#CLIENTSIDE
function onCreated() {
  new 
GuiButtonCtrl("MyButton") {
    
this.join("guifunctions");
    
this.profile GuiButtonProfile;
    
this.text "Some text";
  }
}
function 
MyButton.onAction() {
  
MyButton.changetext("Other text");


I haven't tested this specific one myself, but Inverness' GUI fading works this way; you join the window GUI to a class, and use MyWindow.fadein(), etc.

Though this is probably going to be considered a work-around, I find it more organized.

Chompy 05-10-2009 07:30 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1490677)
Can't you just join the object to a class?

Of course we can, but that's not the point of this thread.

LoneAngelIbesu 05-10-2009 07:48 PM

Quote:

Originally Posted by Chompy (Post 1490713)
Of course we can, but that's not the point of this thread.

Obviously, which is why I mentioned that joining a class is probably a work-around. Personally, I find using a class more organized.

PHP Code:

new GuiControl("toastControl") {
  
this.testFunc = public function() {
    echo(
"Hi there!");
  };


This just looks bad.

Loriel 05-10-2009 08:06 PM

if graal had lua this never happen

Crow 05-10-2009 08:24 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1490717)
Obviously, which is why I mentioned that joining a class is probably a work-around. Personally, I find using a class more organized.

PHP Code:

new GuiControl("toastControl") {
  
this.testFunc = public function() {
    echo(
"Hi there!");
  };


This just looks bad.

Pure preference.

Tigairius 05-10-2009 08:28 PM

Quote:

Originally Posted by LoneAngelIbesu (Post 1490717)
Obviously, which is why I mentioned that joining a class is probably a work-around. Personally, I find using a class more organized.

PHP Code:

new GuiControl("toastControl") {
  
this.testFunc = public function() {
    echo(
"Hi there!");
  };


This just looks bad.

I don't really think it looks that bad and I would prefer it over creating an entire class just to invoke one small function.


All times are GMT +2. The time now is 11:36 AM.

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