What is the purpose of "join"?
My novice scripting skills are coming to the light.
I'm learning both GS2 and scripting with an NPC server for the first time and I see several references to the "join" command. I assume it is used to call code from a class NPCs? Is there a benefit to using "join" over just pasting the code directly into the NPC you're working with? Also I see "this.join" as well. What is the difference between the two commands? |
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:
|
1. You can change the code without changing the level.
2. You can re-use the code elsewhere much easier. 3. You see compiler/script errors right away in RC. |
damn chris out of nowhere
|
Quote:
HTML Code:
function deposit(temp.amountToDeposit) { Does including the variable name in the function act similarly to assigning the variable value? Like "temp.amountToDeposit = player.chat.substring(9).trim());" ? HTML Code:
function onActionServerSide(temp.cmd, temp.amount) { Quote:
|
Quote:
PHP Code:
Quote:
PHP Code:
You're right that substring is similar to tokenize, it could alternatively be written: PHP Code:
So the flow in this script is [play chats clientside] => [trigger is sent from clientside to serverside] => [trigger arrives in onActionServerSide block] => [onActionServerSide block calls this.deposit]. Triggers are a quirky feature of GScript (and I probably should've picked an example that didn't use them -- sorry), there are some good explanations at http://www.graal.net/index.php/Creat.../Helpful_Posts and in particular this post: http://forums.graalonline.com/forums...84&postcount=6 Quote:
|
Thank you for coming back and clarifying, though the confusion was mostly my fault as I misread the original script. And now I know a little more about triggers, so I'm better now for it.
|
One thing I think was not mention which is personally my favorite is having these "utility functions" in one centralized place. Using Chris bank example, If I wanted to add lets say taxes to my bank deposits I would only have to modify that one class oppose to 50 NPCs that are not joined to this class.
|
All times are GMT +2. The time now is 07:04 AM. |
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.