![]() |
Questions about classes
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:
PHP Code:
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? |
I always do something like this whenever I know I'll use a class for both NPC's and players:
PHP Code:
|
Quote:
|
Quote:
|
I personally avoid joining classes to the player. Its simpler to join stuff to weapons and use <WeaponName>.<functionName>() or so.
|
This is what we do on Vesporia:
PHP Code:
PHP Code:
If I have a class that does this: PHP Code:
PHP Code:
PHP Code:
You can use this. to work with the object whether it is joined to a player or an NPC. PHP Code:
|
hmm, use public functions i suppose and just name the weapon?
Here's an example with an inventory kind of system Weapon Name 1 HTML Code:
function onCreated() { HTML Code:
function onEquip() { |
Profiles are objects not strings. The only reason strings work is because Stefan is too nice about fixing peoples scripting errors for them.
new GuiWindowCtrl("TheWindow") { this.profile = GuiWindowProfile; // blah } |
Okay well this answers my question about classes :) Thanks.
As far as joining the functions to the GUI object, the idea I'm getting from you guys for equipping items (since I have a system for custom weapons, I trigger the server for custom weapons to be equipped/unequipped) or similar is to say: -System/WepName1 PHP Code:
PHP Code:
|
All times are GMT +2. The time now is 01:33 PM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.