Author Topic: Type Mismatch  (Read 685 times)

0 Members and 1 Guest are viewing this topic.

Offline Gnintendo

  • Major
  • *
  • Posts: 61
Type Mismatch
« on: January 06, 2008, 06:37:12 pm »
I'm getting the type mismatch error somewhere in this snippet of the code I'm working on, can you help plz:

Code: [Select]
function OnCommand(ID:Byte;Text:string):boolean;
var
  Temp: array[0..5] of string;
  i: integer;
begin
  Result:=false;
  Temp[0]:=LowerCase(GetPiece(Text, ' ', 0)); //Command
  Case Temp[0] of
    '/recompile': begin
      Recompile:= true;
    end;
    '/setexp','/expset': begin
      Temp[1]:=GetPiece(Text, ' ', 1); //Player
      Temp[2]:=GetPiece(Text, ' ', 2); //NewEXP
      if Player[strtoint(Temp[1])].Active=true then begin
        inc(Player[strtoint(Temp[1])].EXP,(strtoint(Temp[2])-Player[strtoint(Temp[1])].EXP));
        WriteConsole(ID,'Player '+Temp[1]+'''s EXP set to '+inttostr(Player[strtoint(Temp[1])].EXP)+'.',$FF20FF20);
      end else WriteConsole(ID,'Player '+Temp[1]+' is inactive.',$FFFF2020);
    end;
  end;
end;

Offline amb2010

  • Camper
  • ***
  • Posts: 264
  • Fear the dot ...
Re: Type Mismatch
« Reply #1 on: January 06, 2008, 08:48:16 pm »
WriteConsole(ID,'Player '+Temp[1]+'''s EXP set to '+inttostr(Player[strtoint(Temp[1])].EXP)+'.',$FF20FF20);

Maybe its the 3 '. Shouldnt it just be one of them?
And as the lyrics go in the United State's national anthem: "America, f**k YEAH!".

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Type Mismatch
« Reply #2 on: January 06, 2008, 09:13:21 pm »
You should also check if text = '/recompile ' + ScriptName sense that also recompiles the script..

WriteConsole(ID,'Player '+Temp[1]+'''s EXP set to '+inttostr(Player[strtoint(Temp[1])].EXP)+'.',$FF20FF20);

Maybe its the 3 '. Shouldnt it just be one of them?
no, thats fine.; first ' to start the string, and '' meaning the ' character.

I would guess that u declared a variable incorrectly.. this compiles:
Code: [Select]
var
  Recompile: boolean;
  Player: array[1..32] of record
    Active: boolean;
    EXP: integer;
  end;

function OnCommand(ID:Byte;Text:string):boolean;
var
  Temp: array[0..5] of string;
  i: integer;
begin
  Result:=false;
  Temp[0]:=LowerCase(GetPiece(Text, ' ', 0)); //Command
  Case Temp[0] of
    '/recompile': begin
      Recompile:= true;
    end;
    '/setexp','/expset': begin
      Temp[1]:=GetPiece(Text, ' ', 1); //Player
      Temp[2]:=GetPiece(Text, ' ', 2); //NewEXP
      if Player[strtoint(Temp[1])].Active=true then begin
        inc(Player[strtoint(Temp[1])].EXP,(strtoint(Temp[2])-Player[strtoint(Temp[1])].EXP));
        WriteConsole(ID,'Player '+Temp[1]+'''s EXP set to '+inttostr(Player[strtoint(Temp[1])].EXP)+'.',$FF20FF20);
      end else WriteConsole(ID,'Player '+Temp[1]+' is inactive.',$FFFF2020);
    end;
  end;
end;