Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-06-2007, 03:59 PM
Twinny Twinny is offline
My empire of dirt
Twinny's Avatar
Join Date: Mar 2006
Location: Australia
Posts: 2,422
Twinny is just really niceTwinny is just really nice
Send a message via AIM to Twinny
Efficiency!

Debate between Kuji and I :Which method is more efficient? My example first then his.

PHP Code:
function ChatBar.onAction()
{
  if (
ChatBar.text != "")
  {
    
temp.toks ChatBar.text.tokenize();
    
temp.args temp.toks;
    
temp.args.delete(0);
    switch(
temp.toks[0])
    {
    
/* Clientside Commands */
      
case "/tailor":
        
Tailor.showTailor();
        return;
      case 
"/reconnect":
        
serverwarp("Theed");
        return;

        ... 

        
/* Serverside Commands */
        
case "mass":
        case 
"admin":
        case 
"test":
          
          ...
          
          
triggerserver("gui"this.nametemp.toks[0], temp.args);
          return;
    }
  }

Clientside commands would be done before the triggerserver while all serverside commands will be triggered.

Compared to:

PHP Code:
function ChatBar.onAction()
{
  if (
ChatBar.text.starts("/"))
  {
    
temp.toks ChatBar.text.tokenize();
    
    
temp.args temp.toks;
    
temp.args.delete(0);
    
    if (
temp.toks[0].substring(1in this.clientcmd)
    {
      
onDoClientCommand(temp.toks[0].substring(1), temp.args);
    }
      else
    {
      
triggerserver("gui"this.nametemp.toks[0], temp.args);
    }
    
    
ChatBar.text "";
  }
}

function 
onDoClientCommand(actionargs)
{
  switch (
action)
  {
    case 
"reconnect":
    {
      
serverwarp("Theed");
    
      return 
true;
    }
  } 
The battle here is between switches and if/else and index() . My method may look longer now but his would have alot of clientside commands as well.

Of course a possibility might be to switch the clientside commands. If not there, check if the command is in an array of serverside commands: if so, serverside. Else displays an error message This may server only make the script look nicer and may have no benefits in efficiency

Last edited by Twinny; 01-06-2007 at 04:11 PM..
Reply With Quote
 


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 07:37 PM.


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