Author Topic: procedure Table  (Read 1816 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
procedure Table
« on: April 27, 2008, 07:10:14 pm »
Function Name: Table
Script Description: Writes a table to a player's console, being aligned correctly
Original Author: Curt
Core Version: 2.6.3
Code:
Code: [Select]
procedure Table(const Id: byte; const TDA: array of array of string; const Color: longint);
var
  i, j: word;
  Echo: string;
  Longest: array of word;
begin
  if (GetArrayLength(TDA) = 0) then exit;
  for i := 0 to GetArrayLength(TDA) - 1 do if (GetArrayLength(TDA[i]) > j) then j := GetArrayLength(TDA[i]);
  SetArrayLength(Longest, j);
  for i := 0 to GetArrayLength(TDA) - 1 do if (GetArrayLength(TDA[i]) > 0) then for j := 0 to GetArrayLength(TDA[i]) - 1 do if (Length(TDA[i][j]) > Longest[j]) then Longest[j] := Length(TDA[i][j]);
  for i := 0 to GetArrayLength(TDA) - 1 do begin
    Echo := '';
    if (GetArrayLength(TDA[i]) = 0) then continue;
    for j := 0 to GetArrayLength(TDA[i]) - 1 do if (GetArrayLength(TDA[i]) > 0) then begin
      Echo := Echo + TDA[i][j];
      if (j <> GetArrayLength(TDA[i]) - 1) then Echo := Echo + Replicate(' ', Longest[j] - Length(TDA[i][j]) + 1);
    end;
    WriteConsole(Id, Echo, Color);
  end;
end;
Note that this is a snippet of code meant for scripters, not server owners
« Last Edit: May 01, 2008, 04:08:56 pm by DorkeyDear »

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: procedure Table
« Reply #1 on: May 01, 2008, 09:02:04 am »
Looks pretty useful. I might change it to a function that returns array's of strings so it can be used for WriteLn aswell and make the space between the lines variable.

Come join: EliteCTF
Listen to: My Music

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: procedure Table
« Reply #2 on: May 01, 2008, 02:32:38 pm »
make the space between the lines variable.
*edits it to make that a variable*
along with making the parameters constants
along with a bug relating to an infinite loop when length of a 2nd degree array being 0
« Last Edit: May 01, 2008, 04:09:22 pm by DorkeyDear »