Author Topic: Points Value [Solved by Port]  (Read 1155 times)

How do I get the value of points from the player list GUI for a specified name?
« Last Edit: January 30, 2012, 06:35:57 AM by jes00 »

Nevermind, for some reason that only worked for the first player on the player list. :/
« Last Edit: January 28, 2012, 06:53:25 AM by Danny Boy »

getField( NPL_List.getRowText( index ), 2 )

getField( NPL_List.getRowText( index ), 2 )
This only gives me the value of the first player's score.
Code: [Select]
%points = getField(NPL_List.getRowText(%name), 2);

This only gives me the value of the first player's score.
Code: [Select]
%points = getField(NPL_List.getRowText(%name), 2);
"index" is a number from 0 - (playerCount - 1), not a name.

This only gives me the value of the first player's score.

Yes, you forgot to change index.

"index" is a number from 0 - (playerCount - 1), not a name.

Yes, you forgot to change index.
No, I changed it to %name.


"index" is a number from 0 - (playerCount - 1), not a name.
Then how can I have it search for a string instead?

Code: [Select]
function getPlayerScore( %name )
{
     %count = NPL_List.rowCount();
     
     for ( %i = 0 ; %i < %count ; %i++ )
     {
          %row = NPL_List.getRowText( %i );
         
          if ( getField( %row, 1 ) $= %name )
          {
               return getField( %row, 2 );
          }
     }
     
     return 0;
}

Code: [Select]
function getPlayerScore( %name )
{
     %count = NPL_List.rowCount();
    
     for ( %i = 0 ; %i < %count ; %i++ )
     {
          %row = NPL_List.getRowText( %i );
          
          if ( getField( %row, 1 ) $= %name )
          {
               return getField( %row, 2 );
          }
     }
    
     return 0;
}
Thanks Port!

EDIT: What are the returns for?
« Last Edit: January 30, 2012, 07:20:23 AM by jes00 »

EDIT: What are the returns for?

They return the value found..?

They return the value found..?
): I still don't understand returns.

They end the function (stops any code below the statement from running) and give back a value.
For example, if you did echo( getPlayerScore( "some name" ) ); - the value that would be echoed is the value that was specified in the return statement.

I'll elaborate with an example.
Code: [Select]
$GrannyWasRaped=1;
function wasGrannyRaped()
{
      if($GrannyWasRaped == 1)
      {
            return "Yes!";
      }
      else
      {
            return "Nope!";
      }
}
function tellMeIfGrannyWasRaped()
{
      echo(wasGrannyRaped());
}
Here you can see that it will echo "Yes!" if $GrannyWasRaped is set to 1, or "Nope!" if it is set to 0.

EDIT: I should also mention the function stops running when it sees a return. This is useful for escaping from bigger functions or loops when you've gotten all the data you need, rather than waiting it out (as in Port's code)
« Last Edit: January 30, 2012, 11:09:34 AM by Slicksilver »