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.name, temp.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(1) in this.clientcmd)
{
onDoClientCommand(temp.toks[0].substring(1), temp.args);
}
else
{
triggerserver("gui", this.name, temp.toks[0], temp.args);
}
ChatBar.text = "";
}
}
function onDoClientCommand(action, args)
{
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