TPlayers.GetByName

From Soldat Community Wiki
Revision as of 07:40, 25 July 2013 by Mighty (talk | contribs) (fixing example, checking if Nil wasn't needed before)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
function GetByName(Name: string): TActivePlayer
 Name: name to be searched for

Description

Returns a TActivePlayer whose name is equal to the searched one. Case sensitive.
Returns Nil if a player was not found.
Warning: Trying to work on a "Nil-player" (result of the function when a player was not found) might throw exceptions or be critical. Remember to make sure a player was found before you try to do anything with him.

Example

Example is trying to find a nickname "~ Mighty" among players and displays proper information to all players (or to player if found).

var 
  p: TActivePlayer;
begin
  p := Players.GetByName('~ Mighty');
  if p = Nil then // important
    Players.Tell('Mighty is not playing here atm ;(')
  else
    p.Tell('Hello Mighty!');
end;