Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting > New Scripting Engine (GS2)
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-19-2006, 08:54 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
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));

Reply With Quote
  #2  
Old 10-19-2006, 08:56 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Definideatly alternative A.
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #3  
Old 10-19-2006, 09:11 PM
contiga contiga is offline
Graal2001 Administration
contiga's Avatar
Join Date: Jul 2004
Location: Netherlands
Posts: 419
contiga is an unknown quantity at this point
Send a message via ICQ to contiga Send a message via AIM to contiga Send a message via MSN to contiga Send a message via Yahoo to contiga
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.
__________________
AIM: Contiga122
MSN: [email protected]
Status:
Quote:
Originally Posted by unixmad View Post
I am also awake 3AM to help correct problems.
Quote:
Originally Posted by Bomy Island RC people
Daniel: HoudiniMan is a bad guy =p
*Bell: rofl. I first read that as houdini is a bad man. like the little kid that wants his mommy to keep her away from that boogie man
Daniel: xD
*Rufus: I wouldn't want my kids around him.
Reply With Quote
  #4  
Old 10-19-2006, 09:19 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
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?
Reply With Quote
  #5  
Old 10-19-2006, 09:25 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by xXziroXx View Post
Definideatly alternative A.
No. Definitely
Quote:
Originally Posted by contiga View Post
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.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #6  
Old 10-19-2006, 09:30 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
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(); 
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #7  
Old 10-19-2006, 09:33 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Same idea. But yes, very efficient nonetheless.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #8  
Old 10-19-2006, 09:35 PM
Yen Yen is offline
Banned
Yen's Avatar
Join Date: Oct 2005
Location: Nova Scotia, Canada
Posts: 1,085
Yen is an unknown quantity at this point
Send a message via AIM to Yen Send a message via MSN to Yen
You can't call clientside functions in a class joined to a player on the serverside, silly.
Reply With Quote
  #9  
Old 10-19-2006, 09:39 PM
xXziroXx xXziroXx is offline
Malorian
xXziroXx's Avatar
Join Date: May 2004
Posts: 5,289
xXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant futurexXziroXx has a brilliant future
Quote:
Originally Posted by Yen View Post
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
__________________
Follow my work on social media post-Graal:Updated august 2025.
Reply With Quote
  #10  
Old 10-26-2006, 08:44 PM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
PHP Code:
function onCreated()
  {
  
mud = (@ "item-" 2345 );
  
mud.getPower();
  } 
??
Reply With Quote
  #11  
Old 10-26-2006, 09:32 PM
Tolnaftate2004 Tolnaftate2004 is offline
penguin.
Join Date: Jul 2004
Location: Berkeley, CA
Posts: 534
Tolnaftate2004 is a jewel in the roughTolnaftate2004 is a jewel in the rough
Send a message via AIM to Tolnaftate2004
Quote:
Originally Posted by Novo View Post
??
We're assuming that there are multiple items.
__________________
◕‿‿◕ · pfa · check yer syntax! · src

Killa Be: when i got that locker in 6th grade the only thing in it was a picture of a midget useing a firehose :/
Reply With Quote
  #12  
Old 10-27-2006, 04:12 AM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
'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'.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:49 PM.


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