Thread: cool summon
View Single Post
  #3  
Old 04-03-2008, 09:41 PM
Chompy Chompy is offline
¯\(º_o)/¯
Chompy's Avatar
Join Date: Sep 2006
Location: Norway
Posts: 2,815
Chompy is just really niceChompy is just really niceChompy is just really nice
Send a message via MSN to Chompy
Quote:
Originally Posted by cbkbud View Post
You might consider using something like this that was posted by me. There is a whole thread about this in the code gallery, called 'Function findName()'.

PHP Code:
public function findName( i ) 
{ 
  
this.look = { "account", "communityname", "nick", "id" }; 
   
  for ( 
temp.a : allplayers ) 
  { 
    for ( 
temp.n : this.look ) 
    { 
      if ( 
makevar( "temp.a." @ temp.n ) == i ) 
      { 
        return 
temp.a.account; 
      } 
    } 
  } 
   
  for ( 
temp.a : allplayers ) 
  { 
    for ( 
temp.n : this.look ) 
    { 
      if ( 
makevar( "temp.a." @ temp.n ).starts( i ) ) 
      { 
        return 
temp.a.account; 
      } 
    } 
  } 
   
  return 
false; 
} 
Which is basically a cleaner, reusable way of what you did.
Actually, she was using a method for finding names that started with the parameter, yours check if it equals.

And Sidney, I would suggest using
PHP Code:
...
for(
temp.i : players) {
  if (
i.account.pos(chat) > -1 || i.nick.pos(chat) > -1  || i.communityname.pos(chat) > -1) {
    
i = i.account;
    break;
  }
}
... 
or something like that, so if their nick/account/community contains the parameter, it will return their account, instead of just checking if their account/nick etc. starts with the parameter

Quote:
Originally Posted by cbkbud View Post
And then please, use braces for each function so you do this:

PHP Code:
if ( true )
{
  
banana();
} 
instead of this:
PHP Code:
if ( true ) banana(); 
Makes it easier to read.
You don't need them if there is a single line action after the if statement, it's all about personal preference.

And it isn't spelled 'braces', that something different
__________________
Reply With Quote