Author Topic: DoDamage script not compiling!  (Read 1104 times)

0 Members and 1 Guest are viewing this topic.

Offline |_ancer

  • Soldier
  • **
  • Posts: 153
  • again and again.
DoDamage script not compiling!
« on: September 07, 2009, 03:46:52 am »
Quote
function OnPlayerCommand(ID: Byte; Text: string): boolean;
var allplayersdie : byte;
    dmgamount : integer;
   temps : string;
begin   
if pos('/dmg ',temps) = 1
   then begin
        temps := Text;
        temps := delete(temps,1,5);
        dmgamount := strtoint(temps);
          for allplayersdie := 1 to NumPlayers do
            DoDamage(allplayersdie, dmgamount)
      end
end;

I cannot find anything wrong in the script and it just won't compile. It keeps on saying 'Type mismatch'. Help!

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: DoDamage script not compiling!
« Reply #1 on: September 07, 2009, 04:57:10 am »
Delete is a procedure that works by reference; it does thus not return a value, but instead modifies the string itself.

tl;dr change temps := delete(temps,1,5); to delete(temps,1,5);.

Offline |_ancer

  • Soldier
  • **
  • Posts: 153
  • again and again.
Re: DoDamage script not compiling!
« Reply #2 on: September 07, 2009, 06:09:52 am »
Quote
09-09-07 21:09:13 
  • DeathDmg -> [Error] (10:9): Identifier expected
It says that when I changed it.

Offline Toumaz

  • Veteran
  • *****
  • Posts: 1904
Re: DoDamage script not compiling!
« Reply #3 on: September 07, 2009, 06:23:53 am »
Code: [Select]
function OnPlayerCommand(ID: Byte; Text: string): boolean;
var
allplayersdie : byte;
    dmgamount : integer;
temps : string;
begin
if pos('/dmg ', temps) = 1 then begin
temps := Text;
Delete(temps, 1, 5);
dmgamount := strtoint(temps);

for allplayersdie := 1 to NumPlayers do
DoDamage(allplayersdie, dmgamount)
end
end;

Offline |_ancer

  • Soldier
  • **
  • Posts: 153
  • again and again.
Re: DoDamage script not compiling!
« Reply #4 on: September 07, 2009, 07:46:34 am »
It compiles but whenever I do /dmg 4000, it doesn't seem to kill anyone.

Offline Polifen

  • Soldier
  • **
  • Posts: 127
Re: DoDamage script not compiling!
« Reply #5 on: September 07, 2009, 09:55:16 am »
You check if temps = /dmg before you set the value, change pos('/dmg ', temps) to pos('/dmg ', Text). Second thing is that it would be better if you use Copy(Text, 1, 5) instead of Pos.

Offline Gizd

  • Flagrunner
  • ****
  • Posts: 586
  • (Re)tired
    • Eat-this! community site
Re: DoDamage script not compiling!
« Reply #6 on: September 07, 2009, 12:12:17 pm »
Code: [Select]
if GetPiece(text,' ',0) = '/dmg' then try
  DoDamage(IntToStr(GetPiece(text,' ',1)), IntToStr(GetPiece(text,' ',2)));
except
  WriteConsole(ID,'/dmg <id> <dmg>',$AA0000);
end;