Author Topic: Out of Range in OnAdminMessage  (Read 1571 times)

0 Members and 1 Guest are viewing this topic.

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Out of Range in OnAdminMessage
« on: August 06, 2010, 07:07:39 am »
Why is this codepart giving me a Out of Range error?

Code: [Select]
procedure OnAdminMessage(IP, Msg: string);

var
i, TcpAdmins : integer;
AdminName : array of string;

begin
  if (GetPiece(Msg,' ',0) = '[ª]') then begin
    TcpAdmins := 1;
      if TcpAdmins > 0 then begin
        for i := 0 to TcpAdmins -1 do
          AdminName[i] := GetPiece(GetPiece(Msg,'[ª] ',1),':',0);
            WriteLn(AdminName[i]);
      end else WriteLn('Error');
  end;
end;

I have no idea whats wrong with it
The truth is out there? Does anyone know the URL?
The URL is here

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Out of Range in OnAdminMessage
« Reply #1 on: August 06, 2010, 08:00:51 am »
The array length of AdminName is 0, you need to set it with SetArrayLength() first.

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: Out of Range in OnAdminMessage
« Reply #2 on: August 06, 2010, 08:40:30 am »
ahh, yes, thank you very much
The truth is out there? Does anyone know the URL?
The URL is here

DarkCrusade

  • Guest
Re: Out of Range in OnAdminMessage
« Reply #3 on: August 07, 2010, 01:46:27 am »
You should use global variables for this so the admin's name is not lost after the procedure ends. However, if you take a closer look at your script you'll notice that 'TcpAdmins' will always be 1. The worst thing is that you don't increase the length of the array whilst idling through the whole list writing the admin's name everywhere and spamming the console with unnecessary messages.

Code: [Select]
var
  AdminName:Array of String;
  TcpAdmins:Byte;

Function AdminNames(Name:String):Boolean;
var
  i:Byte;
begin
  for i := 0 to TcpAdmins-1 do
    if AdminName[i] = Name then begin#
      Result := false;
      break;
    end;
end;

Procedure OnAdminMessage(IP, Msg: string); 
begin
  if (GetPiece(Msg,' ',0) = '[ª]') AND (AdminNames(GetPiece(Msg,' ',0))) then begin
    TcpAdmins := TcpAdmins + 1;
    SetArrayLength(AdminName,TcpAdmins);
    AdminName[TcpAdmins-1] := GetPiece(GetPiece(Msg,'[ª] ',1),':',0);
    WriteLn(AdminName[i]);
  end;
end;

This should be working..

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: Out of Range in OnAdminMessage
« Reply #4 on: August 07, 2010, 09:25:36 am »
uhm, this was just a example codepart, tcp admins and AdminName are global vars in the original script ;)

I have got another problem, somehow
Code: [Select]
if (GetPiece(Msg,' ',0) = '[ª]') is triggered on my local test server, but not on my online server
« Last Edit: August 07, 2010, 09:34:35 am by Stuffy »
The truth is out there? Does anyone know the URL?
The URL is here

Offline dnmr

  • Camper
  • ***
  • Posts: 315
  • emotionally handicapped
Re: Out of Range in OnAdminMessage
« Reply #5 on: August 07, 2010, 10:55:47 am »
it probably doesn't like that weird ª character, try using something else

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: Out of Range in OnAdminMessage
« Reply #6 on: August 07, 2010, 11:33:01 am »
I cant. ª is the only character that isnt changing.
The truth is out there? Does anyone know the URL?
The URL is here

Offline frosty

  • Flagrunner
  • ****
  • Posts: 601
  • Uber Desert Eagle ^^
Re: Out of Range in OnAdminMessage
« Reply #7 on: August 13, 2010, 07:37:36 am »
if its using a value that isnt going to change then use a const, give it a reasonable name, etc

example, using your code:
Code: (pascal) [Select]
const
yourvar = '0'; //or whatever, but since in your code this is used as a string i have given it a string value

var
//your vars here

Function AdminNames(Name:String):Boolean;
var
  i:Byte;
begin
  for i := 0 to TcpAdmins-1 do
    if AdminName[i] = Name then begin#
      Result := false;
      break;
    end;
end;

Procedure OnAdminMessage(IP, Msg: string); 
begin
  if (GetPiece(Msg,' ',0) = '[yourvar]') AND (AdminNames(GetPiece(Msg,' ',0))) then begin
    TcpAdmins := TcpAdmins + 1;
    SetArrayLength(AdminName,TcpAdmins);
    AdminName[TcpAdmins-1] := GetPiece(GetPiece(Msg,'[yourvar] ',1),':',0);
    WriteLn(AdminName[i]);
  end;
end;

hope this helps
check out my server! click here

If at first you don't succeed, Improvise! :D

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: Out of Range in OnAdminMessage
« Reply #8 on: August 13, 2010, 08:14:42 am »
nah this wont work, its a ubuntu-based problem
The truth is out there? Does anyone know the URL?
The URL is here

Offline tk

  • Soldier
  • **
  • Posts: 235
Re: Out of Range in OnAdminMessage
« Reply #9 on: August 13, 2010, 09:12:37 am »
It's not a ubuntu based problem
I don't remember exactly what char clientlist uses. 170?
If so try '[' + #170 + ']' ...