Author Topic: [Solved] Darn it! Integers and strings issues..  (Read 620 times)

0 Members and 1 Guest are viewing this topic.

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
[Solved] Darn it! Integers and strings issues..
« on: July 04, 2010, 11:57:51 pm »
Hey peeps, kinda late eh?

Well i've been trying to fix this script for more than 2 hours now ( Yes this little piece of script, HA )

I just want to add + 1 in the players's .log doc.
Like by example, Vince.log has number 1 in it. When i do the wanted thing, it will add +1 in Vince.log, so it'd be like 2 in it.

Just getting problems like : '1' isn't an integer value

Code: (pascal) [Select]
const

SD = 'scripts/hnstop/players/';

procedure AppOnIdle(Ticks: integer);
 var
 i : byte;
 Encode : integer;
  begin
   if (NumPlayers > 0) and (DeltaPlayers = 1) then begin
     for i := 1 to 32 do begin
    if GetPlayerStat(i,'team') = 4 then begin
     if FileExists(SD + IDToName(i) + '.log') = true then begin
     Encode := StrToInt(ReadFile(SD + IDToName(i) + '.log')) + 1;
     WriteFile(SD + IDToName(i) + '.log', IntToStr(Encode));       
     Command('/setteam1 ' + inttostr(i));
     end;
    // StrToInt(ReadFile(SD + md5string(IDToName(i)) + '.log')) = Encode
    if FileExists(SD + IDToName(i) + '.log') = false then begin
     WriteFile(SD + IDToName(i) + '.log', IntToStr(1));
     Command('/setteam1 ' + inttostr(i)); 
     end;
     end;
   end;
   end;
   end;

This is just pissin' me off 'cause i just got back at scripting and this s**t happens ..

Thanks for further help.
« Last Edit: July 05, 2010, 09:56:24 am by VinceBros »

Offline Stuffy

  • Soldier
  • **
  • Posts: 182
  • Very stuffy.
    • Climb-Zone Forum
Re: Darn it! Integers and strings issues..
« Reply #1 on: July 05, 2010, 06:35:00 am »
Just do

Code: [Select]
WriteFile(SD + IDToName(i) + '.log', '1');
The truth is out there? Does anyone know the URL?
The URL is here

Offline Swompie

  • Camper
  • ***
  • Posts: 390
Re: Darn it! Integers and strings issues..
« Reply #2 on: July 05, 2010, 06:53:51 am »
Code: (pascal) [Select]
function ReadFromFile(Filename: string): string;
begin
  Result := ReadFile(Filename);
  Result := Copy(Result, 1, Length(Result) - 2);
end;
Use this instead of ReadFile because there will be always a linebreak at the end of the file causing the ".. isn't a valid integer value" or similar errors.

Offline VinceBros

  • Soldat Beta Team
  • Camper
  • ******
  • Posts: 275
Re: Darn it! Integers and strings issues..
« Reply #3 on: July 05, 2010, 09:56:12 am »
Thanks bud, no more problems now :)