The idea behind join is that you can put common utility code in classes, and then "join" that code onto weapons and NPCs in order to re-use it. It's like you're copying-and-pasting the code from the class onto the weapon/NPC, but without actually duplicating it.
For example, let's say you wrote a function which reverses a string. You could put in a class called func_strings, and then join func_strings anywhere you want to call that function from.
I think maybe this old post about classes might help as well:
Quote:
Originally Posted by cbk1994
All a class does is extend a weapon or NPC. It doesn't stand on its own.
Class functions_bank
PHP Code:
function deposit(temp.amountToDeposit) {
// obviously this is just an example, don't actually use this
player.rupees -= temp.amountToDeposit;
player.bank += temp.amountToDeposit;
}
Weapon ATM
PHP Code:
function onCreated() {
this.join("functions_bank");
}
function onActionServerSide(temp.cmd, temp.amount) {
if (temp.cmd == "deposit") {
this.deposit(temp.amount);
}
}
//#CLIENTSIDE
function ChatBar.onAction() {
if (ChatBar.text.starts("/deposit")) {
triggerServer("gui", this.name, "deposit", player.chat.substring(9).trim());
}
}
The example above shows a very simple use of classes.
When you use join(classname) on a weapon or an NPC, imagine the script of the class being copied and pasted into the weapon. You can't pass things to a class; classes extend an object. They aren't their own objects.
|
In general I don't think there's a difference between "join" and "this.join", but in some cases you have a reference to a player, NPC, or weapon, and want to join it to that. For example, it's valid to write something like
findNPC("MyNPC").join("my_class");. Personally I always used the
this as I think it's a bit more explicit.