Revision [731]

This is an old revision of join made by WhiteDragon on 2010-06-03 03:38:42.
 
Usage

Syntax: TGraalVar.join(class);


Explanation

Joining a class provides its functions to whatever script that joined it.

While you can think join as "copying and pasting" the class into your script, it does more than that. It will
  1. keep track of your joined classes (see joinedclasses and isinclass);
  2. allow you to get rid of joined classes (see leave); and
  3. allow you to call a function in a specific joined class (see ::).


Separating reusable code into another class and then joining it often helps reduce duplicate code on the server, and because of that, makes it easier to maintain scripts.

Serverside Join
A serverside join is run on the server -- so if it is put in the onCreated block, it will run when the weapon/npc is created/updated. Joining serverside will give access to both serverside and clientside functions.

Clientside Join
A clientside join is run on the client. There can sometimes be a significant delay between when join is called and when you actually have access to the functions in the joined class. Joining clientside will only give access to clientside functions.


It is recommended to join serverside because the lag created by a clientside join is often troublesome, as the calling function will keep running and may except certain functions to exist, even though they do not yet (see isclassloaded).


Example

example_class
function example_function() {
  echo("Hello!");
}


Example Weapon
function onCreated() {
  this.join("example_class");
  example_function();
}

... would echo "Hello!" on the server RC when the weapon is updated.

Categories

CategoryFunctionClientside
CategoryFunctionServerside

There are no comments on this page. [Add comment]

Valid XHTML 1.0 Transitional :: Valid CSS :: Powered by WikkaWiki