Thread: Efficiency!
View Single Post
  #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