Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Comprehension of classes (https://forums.graalonline.com/forums/showthread.php?t=77744)

Nabru 11-28-2007 11:59 PM

Comprehension of classes
 
Hi, most of you knew me as a decent scripter, but after 2 years of playing WoW I forgot most of my knowledge of GS2. Something I never did understand was classes and how to utilize them. I know in C++ classes can be used for a multitude of useful things, I'm wondering if the same thing applies with GScript?

For example: Can I call a class(join(X); )

and then later in the script use a string or command set in that class without error? If this currently doesn't exist I think it'd be an awesome idea..

Twinny 11-29-2007 12:32 AM

I think of Graal classes as include functions.

Class: bob
PHP Code:

function bob()
  return 
"Hi! I'm Bob!"

Weapon: Jane
PHP Code:

function onCreated()
{
  
this.join("bob");
  
temp.statement bob();
  echo(
temp.statement);



Tolnaftate2004 11-29-2007 12:37 AM

Classes in GScript are probably more closely related to header files in C++ (or object files, even); join is somewhat like #include (or your linker).

coreys 11-29-2007 12:41 AM

Yeah, classes are more like objects in C++, as far as I know.
Classes in Graal are very much like inserting the code of a class into any other script. You can also unjoin (so to speak) classes by using the leave() command. Also, onCreated() in the class is separate from onCreated() in the script you join a class to. onCreated() in a class is called when the class is joined.

Nabru 11-29-2007 01:10 AM

Just the type of responses I was looking for, thanks guys :)

coreys 11-29-2007 01:44 AM

Quote:

Originally Posted by Angel_Light (Post 1361125)
also, little common sense, classes must be joined serverside.

Uhm.
No. o_o
When you join something serverside it only uses the serverside portion of the class, and vice versa.

cbk1994 11-29-2007 01:48 AM

Quote:

Originally Posted by Angel_Light (Post 1361125)
also, little common sense, classes must be joined serverside.

Wrong. It's a good idea to, but when you have a player class, it needs to be joined clientside.

You can't join clientside, then use functions serverside, but it does work vica-versa. I always join serverside, except for player functions.

Classes are a way to make a standard object, or a stand script. For example, for a staff block you might want to make a class so that you can just putnpc2, then join the class, rather then putting in the whole script. And this way, if you need to change something, you can.

Another way to use classes are to provide functions.

Class foo
PHP Code:

function onCreated()
{
  echo( 
"moo" );


Script in level MYLEVELDONTTOUCH.nw
PHP Code:

join"foo" ); 

Will echo "moo" in RC.

EDIT:
Also you said
Quote:

When you join something serverside it only uses the serverside portion of the class, and vice versa.
That's incorrect. When you join serverside, you get serverside & clientside functions, but when you join clientside you only get clientside functions.

coreys 11-29-2007 03:00 AM

Quote:

Originally Posted by cbkbud (Post 1361130)
Stuff

Also wrong. You can join serverside and clientside just fine. And player classes generally ARE joined serverside. o.O

Inverness 11-29-2007 03:02 AM

Quote:

Originally Posted by Angel_Light (Post 1361125)
also, little common sense, classes must be joined serverside.

No, clientside classes are supported fully now.

And when joining serverside, you only get the clientside functions if that object has an instance of it clientside, like weapons or npcs in levels. Though players don't appear to work like that, from what little I experimented at least.

coreys 11-29-2007 03:08 AM

Quote:

Originally Posted by Inverness (Post 1361153)
No, clientside classes are supported fully now.

And when joining serverside, you only get the clientside functions if that object has an instance of it clientside, like weapons or npcs in levels. Though players don't appear to work like that, from what little I experimented at least.

Er, yeah my bad. But in clientside, the serverside portion of a class won't work when joined.

Twinny 11-29-2007 04:12 AM

Quote:

Originally Posted by cbkbud (Post 1361130)
Wrong. It's a good idea to, but when you have a player class, it needs to be joined clientside.

Or not? I join classes during the player login event and that's serverside :whatever:

cbk1994 11-29-2007 04:46 AM

Sorry, I was unclear.

I mean that for a player class with clientside functions, it needs to be joined clientside.

I join my player classes serverside in the control-npc script, but for the clientside functions, you have to join clientside.

Sorry if I was unclear.

coreys 11-29-2007 05:04 AM

Quote:

Originally Posted by cbkbud (Post 1361165)
Sorry, I was unclear.

I mean that for a player class with clientside functions, it needs to be joined clientside.

I join my player classes serverside in the control-npc script, but for the clientside functions, you have to join clientside.

Sorry if I was unclear.

I'm pretty sure you don't have to join on both ends, but I guess it would be good practice to do that anyways.

cbk1994 11-29-2007 05:06 AM

Quote:

Originally Posted by coreys (Post 1361172)
I'm pretty sure you don't have to join on both ends...

You don't for normal classes, but when joining to a player you do. ^^

For other classes, always join serverside.


All times are GMT +2. The time now is 04:22 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.