Author Topic: counting kills and deaths.. errorss  (Read 1253 times)

0 Members and 1 Guest are viewing this topic.

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
counting kills and deaths.. errorss
« on: April 30, 2007, 10:33:26 pm »
Well, I'm new with these scripts, to the language and everything, so I need some help.

Here is my code:

Quote
type
   TPlayer = record
      nick: string;
      kills: integer;
      deaths: integer;
   end;

var
   P: array of TPlayer;
   PT: array of TPlayer;
   sending: boolean;


procedure ActivateServer();
begin
   sending := false;
end;


procedure OnPlayerKill(Killer, Victim: byte; Weapon: string);
var
   k_nick, v_nick: string;
   i, c: integer;
   player: array of TPlayer;
   k, v: boolean;
begin
   k_nick := IDToName(Killer);
   v_nick := IDToName(Victim);

   //Search name on arrays and update kills and deaths

   player := P;
   if sending = true then begin
      player := PT;
   end;

   c := Length(player) - 1;
   k := false;
   v := false;

   for i := 0 to c do
   begin
      if player.nick = k_nick then begin
         player.kills := player.kills + 1;
         k := true;
      end;
      if player.nick = v_nick then begin
         player.deaths := player.deaths + 1;
         v := true;
      end;

      if k = true and v = true
      then i := c + 1;
   end;

   if k = false then begin
      SetLength(player, c + 2);
      player[c + 1].kills := 1;
      player[c + 1].deaths := 0;
      player[c + 1].nick := k_nick;
   end;

   if v = false then begin
      SetLength(player, c + 2);
      player[c + 1].kills := 0;
      player[c + 1].deaths := 1;
      player[c + 1].nick := v_nick;
   end;
end;

function Send();
var
   i, c: integer;
   result: string;
   error: boolean;
begin
   sending := true;

   //Send data

   c := Length(P) - 1;
   error := false;

   for i := 0 to c do
   begin
      result := GetURL([...]);
      if result <> "SUCCESS" then
      begin
         error := true;
         i := c + 1;
      end
      else
      begin
         P.kills := 0;
         P.deaths := 0;
      end;
   end;

   if error == false then begin
      SetLength(P, 0);
      P := Copy(PT, 0, Length(PT));
      SetLength(PT, 0);
   end;

   sending := false;
end;

procedure AppOnIdle(Ticks: integer);
begin
   if Ticks mod (3600*5) = 0 then begin
      Send();
   end;
end;

I get a type mismatch error when i try to run it. Is there a way to know on what line the error is?

My only guess is that I messed up things assignig player = P, which are arrays, but i want to make sure with your help.

I'm sorry for posting the whole code, but i really don't know where the error is.
urraka

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: counting kills and deaths.. errorss
« Reply #1 on: April 30, 2007, 10:52:03 pm »
It tells you what line the error is, next to where it says Type Mismatch.

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: counting kills and deaths.. errorss
« Reply #2 on: April 30, 2007, 10:54:35 pm »
yeah it gives a number... (158:25) which makes no sense for me
urraka


Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: counting kills and deaths.. errorss
« Reply #4 on: April 30, 2007, 11:05:55 pm »
oh i see, too bad my script only has 113 lines :P

is there something i'm missing?, maybe i have to count the lines of the other included scripts? :S

ok i cheked and it seemed i had to count the other scripts lines the error was in this line

c := Length(player) - 1;

why? :(
« Last Edit: April 30, 2007, 11:12:51 pm by PerroAZUL »
urraka

Offline EnEsCe

  • Retired Soldat Developer
  • Flamebow Warrior
  • ******
  • Posts: 3101
  • http://enesce.com/
    • [eC] Official Website
Re: counting kills and deaths.. errorss
« Reply #5 on: April 30, 2007, 11:55:33 pm »
Length is not used for arrays.... you use getarraylength(array) for arrays.

Offline urraka

  • Soldat Developer
  • Flagrunner
  • ******
  • Posts: 703
Re: counting kills and deaths.. errorss
« Reply #6 on: May 02, 2007, 08:52:53 am »
ok thanks for that, i guess the documentation i read in the web posted in "The Basics" sticky is wrong then

Date Posted: 01/05/2007 - 17:29:10
is there a Copy function for arrays?
urraka