Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   Function library efficiency (https://forums.graalonline.com/forums/showthread.php?t=69525)

Yen 10-19-2006 08:54 PM

Function library efficiency
 
Which of the following cases would be more efficient? I'm pretty sure I know which, but I'd like some input from eithers.
Both cases are clientside.

The first case (a) is to create a class to hold groups of functions, then join it to NPCs that require functions that deal with certain objects.
i.e.
PHP Code:

// Class - mudfunctions
//#CLIENTSIDE
function GetItemPower(itemid) {
  return (@
"item-" itemid).power;


PHP Code:

// Some other weapon
//#CLIENTSIDE
function onCreated() {
  
join("mudfunctions");
  echo(
GetItemPower(3324));


The second case (b) is to create a weapon for each group of functions and refer a global variable to itself in the onCreated block.
i.e.
PHP Code:

// Weapon - MUD Library Functions
//#CLIENTSIDE
function onCreated() {
  
mud this;
}

public function 
GetItemPower(itemid) {
  return (@
"item-" itemid).power;


PHP Code:

// Some other weapon
//#CLIENTSIDE
function onCreated() {
  echo(
mud.GetItemPower(3324));



xXziroXx 10-19-2006 08:56 PM

Definideatly alternative A.

contiga 10-19-2006 09:11 PM

Alternative C, which is:
PHP Code:

//Class - mud
//#CLIENTSIDE
function GetItemPoweritemid)
  return ( @ 
"item-" itemid).power

PHP Code:

//Some weapon
this.join"mud");
//#CLIENTSIDE
function onCreated()
  echo( 
mud::GetItemPower3324)); 

Else
Alternative B.

Yen 10-19-2006 09:19 PM

That would require more resource, and declaring the class you're calling isn't needed if you're an organized scripter.

Actually, it's the exact same thing I posted, just written in a less efficient manner. Why the hell did you waste precious forum bytes?

Tolnaftate2004 10-19-2006 09:25 PM

Quote:

Originally Posted by xXziroXx (Post 1233181)
Definideatly alternative A.

No. Definitely
Quote:

Originally Posted by contiga (Post 1233197)
Alternative C, which is:
PHP Code:

//Class - mud
//#CLIENTSIDE
function GetItemPoweritemid)
  return ( @ 
"item-" itemid).power

PHP Code:

//Some weapon
this.join"mud");
//#CLIENTSIDE
function onCreated()
  echo( 
mud::GetItemPower3324)); 


No.

B.
If you have >1 weapon all joining the same class (and I'm assuming there's more than one function in that class), it is less efficient to load each of those weapons with code that is unneeded for that weapon (say the weapon only uses one of many functions) using join() than to have each of these weapons calling a public function in a single existance of the library.

If that's the only function in the class, the different is negligible.

xXziroXx 10-19-2006 09:30 PM

Well, I personally would most likely do:

Class
PHP Code:

function funcName()
{
  
// Stuff


Control-NPC
PHP Code:

function onActionPlayerOnline()
{
  
player.join("class");


Trigger
PHP Code:

player.funcName(); 


Tolnaftate2004 10-19-2006 09:33 PM

Same idea. But yes, very efficient nonetheless.

Yen 10-19-2006 09:35 PM

You can't call clientside functions in a class joined to a player on the serverside, silly.

xXziroXx 10-19-2006 09:39 PM

Quote:

Originally Posted by Yen (Post 1233211)
You can't call clientside functions in a class joined to a player on the serverside, silly.

Must have missed the "both cases are clientsided" part :rolleyes:

Novo 10-26-2006 08:44 PM

PHP Code:

function onCreated()
  {
  
mud = (@ "item-" 2345 );
  
mud.getPower();
  } 

??

Tolnaftate2004 10-26-2006 09:32 PM

Quote:

Originally Posted by Novo (Post 1236384)
??

We're assuming that there are multiple items.

Admins 10-27-2006 04:12 AM

'A' would be the nicest solution, although not necessary the most efficient, because currently class scripts are not cached (need to be downloaded on first use) and the requested function might not exist yet when the class is not loaded yet (onCreated() is not called then either, even if it would be cached).

'B' is more efficient because weapons are cached, and most of the time item systems require some central control script anyway (which is creating the item objects).

If you can live with the delay of the class script loading then 'A' would be best I guess, otherwise use 'B'.


All times are GMT +2. The time now is 05:38 AM.

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