Author Topic: Splitting adding '0' at end?  (Read 937 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Splitting adding '0' at end?
« on: June 07, 2007, 04:01:55 pm »
Code: [Select]
procedure LoadMapData(Filename: string);
var
  i,j,k: integer;
  Line,Semi,Data: TStringArray;
begin
  Line := Split(ReadFile(Filename),Chr(13) + Chr(10));
  for i := 0 to ArrayHigh(Line) - 1 do begin
    Semi := Split(Line[i],';');
    for j := 1 to ArrayHigh(Semi) do begin
      Data := Split(Semi[j],',');
Command('/say ' + InttoStr(i) + ',' + InttoStr(j) + ',' + Data[0]);
    end;
  end;
end;
It adds a 0 to the end of the number it first got when i = 0 and j = 1

Filename is MapData.txt which contains:
Quote
Airpirates;70,244,-745,-1190;0,0,0,0;0,0,0,0;0,0,0,0
Arena3;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0
Bigfalls;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0
Bridge;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0
Factory;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0
Island2k5;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0
Jungle;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0
RatCave;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0
Rok;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0

LoadMapData is called under ActivateServer

Offline KeYDoN

  • Major
  • *
  • Posts: 60
Re: Splitting adding '0' at end?
« Reply #1 on: June 07, 2007, 04:05:34 pm »
why j start with j=1 ?

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: Splitting adding '0' at end?
« Reply #2 on: June 07, 2007, 04:10:56 pm »
Clear up the arrays before using them.
Also is that "- 1" your intention, i think ti shouldn't be there.

Code: [Select]
procedure LoadMapData(Filename: string);
var
  i,j,k: integer;
  Line,Semi,Data: TStringArray;
begin
  Line := Split(ReadFile(Filename),Chr(13) + Chr(10));
  for i := 0 to ArrayHigh(Line) - 1 do begin
    SetArrayLength(Semi, 0);
    Semi := Split(Line[i],';');
    for j := 1 to ArrayHigh(Semi) do begin
      SetArrayLength(Data, 0);
      Data := Split(Semi[j],',');
      Command('/say ' + InttoStr(i) + ',' + InttoStr(j) + ',' + Data[0]);
    end;
  end;
end;

Hope it helps... i've had trouble with arrays and split before and got solved doing this.
« Last Edit: June 07, 2007, 04:12:41 pm by PerroAZUL »
urraka

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Splitting adding '0' at end?
« Reply #3 on: June 07, 2007, 04:25:51 pm »
I'm not really sure about that "- 1" but I know that there was an extra line at the end when I just had ArrayHigh.

Thanks a ton. You'd think that it would easily overwrite the old values, not make a mess of problems. :)