My understanding about classes is that when you join a class to an object, the 'this' object in the class becomes the object you joined the class to. So if you joined a class to a player, obviously 'this' would be this player who triggered the class function to be called.
I'm wondering if the 'this' rule of classes applies to all other objects aside from the player. So that if you join a class to a level NPC, 'this' would be the NPC the class is joined to.
One would wonder how I've gone this long without clarifying this basic idea about classes, but here I am :P
My more specific question stems from the same general question about classes. I want to join a class to my GUIs to reduce the clutter in some of my system weapons. I want to add functions to my GUIs (for example Inventory.toggle()) but I'm having a hard time getting my functions to call.
My idea to do this would be:
PHP Code:
//#CLIENTSIDE
function DrawWindow() {
new GuiWindowCtrl( "TestWindow" ) {
this.join( "testwindowfunctions" );
//window attributes
}
}
function onKeyPressed( cd , ky ) {
if ( ky == "Q" ) TestWindow.Toggle();
if ( !TestWindow.Toggle() ) DrawWindow();
}
Which would trigger:
PHP Code:
//#CLIENTSIDE
public function Toggle() {
echo( "Object: " @ this );
if ( this.visible ) this.destroy();
else return false;
}
I have a script similar to this running in an inventory window, but I can't seem to call the class.
Don't know if this is a very practical way of doing things. Mainly I'm just looking for some clarifications about this stuff. And if anyone has any better ideas on how organize the GUI scripts that is always welcome too. =)
UPDATE:
The above script probably wouldn't work because the function is called before the class ever has a chance to be joined to the object. How can I join the class to the object to do something like that if the class is supposed to be triggering the window to be created in the first place?