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

  
this.look = { "account""communityname""nick""id" }; 
   
  for ( 
temp.allplayers 
  { 
    for ( 
temp.this.look 
    { 
      if ( 
makevar"temp.a." temp.) == 
      { 
        return 
temp.a.account
      } 
    } 
  } 
   
  for ( 
temp.allplayers 
  { 
    for ( 
temp.this.look 
    { 
      if ( 
makevar"temp.a." temp.).starts) ) 
      { 
        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.players) {
  if (
i.account.pos(chat) > -|| i.nick.pos(chat) > -1  || i.communityname.pos(chat) > -1) {
    
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