<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE funcs
  SYSTEM '../../../clonk.dtd'>
<?xml-stylesheet type="text/xsl" href="../../../clonk.xsl"?>
<funcs>
  <func>
    <title>SetScoreboardData</title>
    <category>Interface</category>
    <version>5.1 OC</version>
    <syntax>
      <rtype>bool</rtype>
      <params>
        <param>
          <type>int</type>
          <name>row_id</name>
          <desc>Value greater than to equal to 0 or SBRD_Caption. Index of the row in which you want to set data. The constant SBRD_Caption indicates the first column which is to be used as column header.</desc>
        </param>
        <param>
          <type>int</type>
          <name>coloumn_id</name>
          <desc>Value greater than to equal to 0 or SBRD_Caption. Index of the column in which you want to set data. The constant SBRD_Caption indicates the first row which is to be used as row header.</desc>
        </param>
        <param>
          <type>string</type>
          <name>text</name>
          <desc>Text data to be set. If unspecified or 0, the cell is cleared. If a row is completely empty except for the header (SBRD_Caption), the row is removed. The same applies to columns. Row or column removal is only performed after clearing of a cell.<br/>To display symbols or text in different colors you can use markup.</desc>
          <optional />
        </param>
        <param>
          <type>int</type>
          <name>data</name>
          <desc>Extra data for these cells. This data is used to sort the scoreboard using <funclink>SortScoreboard</funclink>.</desc>
          <optional />
        </param>
      </params>
    </syntax>
    <desc>Sets data in the scoreboard. The scoreboard is a global data table which can be used by scenarios to keep track of each player's score or other data. By default, the scoreboard can be displayed with the Tab key but display can also be controlled using <funclink>DoScoreboardShow</funclink>.<br/> The scoreboard is automatically created when data is set and automatically removed when all data is cleared.<br/> Data is set using a row and column index. If the row or column of a specified index does not yet exist, it is created as soon as data in this row or column is set. It does not matter which numeric indices you use as long as they are unique. So you could also use player numbers, player IDs (see <funclink>GetPlayerID</funclink>), or team IDs (see <funclink>GetPlayerTeam</funclink>) as row or column index. In order to prevent different object scripts from accidentally using the same row or column index you can use the <funclink>ScoreboardCol</funclink> function which will create a unique column index from a given value. In this case you should still take care that all object scripts accessing the scoreboard are using matching row indices. Rows and columnd are not sorted by row or column index. You can use the <funclink>SortScoreboard</funclink> function for user defined sorting.</desc>
    <remark>The cell in the top left corner is never displayed. Instead, the value for row_id == SBRD_Caption and coloumn_id == SBRD_Caption is displayed in the header. If no value is specified here, the scoreboard will not have a header and can not be moved using the mouse.</remark>
    <examples>
      <example>
        <code>protected func InitializePlayer(int player)
  {
  var player_id = <funclink>GetPlayerID</funclink>(player), coloumn_id = 1;
  SetScoreboardData(SBRD_Caption, coloumn_id,   &quot;{{RVLR}}&quot;,                coloumn_id);
  SetScoreboardData(player_id,    coloumn_id,   &quot;0&quot; ,                      0);
  SetScoreboardData(SBRD_Caption, SBRD_Caption, &quot;Score&quot;,                   SBRD_Caption);
  SetScoreboardData(player_id,    SBRD_Caption, <funclink>GetTaggedPlayerName</funclink>(player), player_id);
  <funclink>SortScoreboard</funclink>(coloumn_id, true);
  <funclink>Global</funclink>(player)=0;
  return true;
  }</code>
        <text>This might be a typical function for intializing the scoreboard in a scenario script: for each player a row is created. The row header is the player name and another column per row contains the starting score of 0.<br/> To index the rows we are using the player id (iPlrID). This player id is unique for each joined player so newly joining or rejoining players will get a unique id as well. 1 is used as column index for the score.<br/> The first call to SetScoreboardData sets the header of the score column to "{{RVLR}}"; which will display the picture of the rule object "Rivalry". The second call enters a "0" into the score column for the joining player. The third call sets the scoreboard title to "Score". The fourth call sets the row header (meaning the left column) to the player name and player color of the joining player.<br/> By using <funclink>SortScoreboard</funclink> the scoreboard is then sorted in descending order. The global variable of player index is then set to 0 so we can keep track of the player's score here.</text>
        <code>protected func RemovePlayer(int player)
  {
  var player_id = <funclink>GetPlayerID</funclink>(player), coloumn_id = 1;
  SetScoreboardData(player_id, coloumn_id, 0 ,0);
  }</code>
        <text>Another function in the same scenario script would remove the cell in the score column of a deleted player. If no other scripts have accessed the scoreboard, this would effectively completely remove the player from the scoreboard, since no other cells except headers would contain any data.</text>
        <code>public func AddScore(int player)
  {
  var player_id = <funclink>GetPlayerID</funclink>(player), coloumn_id = 1, iScore = ++<funclink>Global</funclink>(player);
  SetScoreboardData(player_id, coloumn_id, <funclink>Format</funclink>(&quot;%d&quot;, iScore), iScore);
  <funclink>SortScoreboard</funclink>(coloumn_id, true);
  <funclink>DoScoreboardShow</funclink>(1, player+1);
  <funclink>Schedule</funclink>(<funclink>Format</funclink>(&quot;<funclink>DoScoreboardShow</funclink>(-1, %d)&quot;, player+1), 200);
  }</code>
        <text>Finally, this function will add a score point for a player. The score is also set as extra data so the list can automatically be sorted by score.<br/> Using <funclink>DoScoreboardShow</funclink> the scoreboard is displayed for the player receiving the point. The following call to Schedule will then hide the scoreboard after a few seconds (200 frames).</text>
      </example>
    </examples>
    <related>
      <funclink>SortScoreboard</funclink>
      <funclink>DoScoreboardShow</funclink>
      <funclink>ScoreboardCol</funclink>
    </related>
  </func>
  <author>Sven2</author><date>2006-02</date>
</funcs>
