Difference between revisions of "TPlayers.GetByName"

From Soldat Community Wiki
Jump to: navigation, search
(new page)
 
m (fixing example, checking if Nil wasn't needed before)
 
Line 8: Line 8:
  
 
== Example ==
 
== Example ==
Example is trying to find a nickname "~ Mighty" among players and displays proper information to all players.
+
Example is trying to find a nickname "~ Mighty" among players and displays proper information to all players (or to player if found).
 
<syntaxhighlight lang="pascal">
 
<syntaxhighlight lang="pascal">
 
var  
 
var  
Line 17: Line 17:
 
     Players.Tell('Mighty is not playing here atm ;(')
 
     Players.Tell('Mighty is not playing here atm ;(')
 
   else
 
   else
     Players.Tell('Hello Mighty!');
+
     p.Tell('Hello Mighty!');
 
end;
 
end;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:TActivePlayer]]
 
[[Category:TActivePlayer]]

Latest revision as of 07:40, 25 July 2013

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;