Author Topic: Function types and result  (Read 3137 times)

0 Members and 1 Guest are viewing this topic.

Offline said3Topic starter

  • Jr. Member
  • **
  • Posts: 51
  • Activity:
    0%
  • Reputation Power: 1
  • said3 has no influence.
  • Respect: +20
  • Referrals: 2
    • View Profile
Function types and result
« on: April 24, 2017, 04:16:04 AM »
0
Hi all,

I am having an issue trying to debug a script that I have not written myself but as some of us do, tweak to our needs. This is the part that I cannot understand why it does not work
Spoiler: show
function CheckTiles:Array of array of Integer;
var
X0,Y0,i,q,x,y,One,Two:Integer;
StaticData:TStaticCell;
h:Byte;
TSTData:TStaticTileData;
Tiles:Array of array of Integer;
begin
  for i:=0 to 33 do begin
    x:=-15;
    y:=2;
    if i>0 then begin
      if One=Two then begin
        Inc(One);
      end
      else begin
        Inc(Two);
      end;
    end;
    While True do begin
      X0:=GetX(Self)+x+One;
      Y0:=GetY(Self)+y+Two;
      StaticData:=ReadStaticsXY(X0,Y0,WorldNum);
      if GetLayerCount(X0,Y0,WorldNum)<1 then begin
        if x>2 then break;
        Inc(x);
        Dec(y);
        Continue;
      end;
      TSTData:=GetStaticTileData(StaticData.Statics[0].Tile);
      h:=TSTData.Height;
      if (StaticData.Statics[0].Tile>3275) and (StaticData.Statics[0].Tile<3300) then begin
        SetLength(Tiles, q+1);
        SetLength(Tiles[q], 4);
        Tiles[q][0]:=StaticData.Statics[0].Tile;
        Tiles[q][1]:=StaticData.Statics[0].X;
        Tiles[q][2]:=StaticData.Statics[0].Y;
        Tiles[q][3]:=StaticData.Statics[0].Z;
        if x>2 then break;
        Inc(q);
        Inc(x);
        Dec(y);
        Continue;
      end
      else begin
        if x>2 then break;
        Inc(x);
        Dec(y);
        Continue;
      end;
    end;
  end;
  Result:=Tiles;
end;

The function is declared as array of array of integer, and the variable that I want to return is another array of array of integers, but when I try to compile the script. It pops up an issue saying Result and tiles are not the same type therefore it stops...

Any help with this please? I am sure it is a silly thing but I cannot figure it out on my own...

Thanks in advance

Offline Vizit0r

  • Stealth Developer
  • Newbie
  • *
  • Posts: 9
  • Activity:
    0%
  • Reputation Power: 1
  • Vizit0r has no influence.
  • Respect: +1
  • Referrals: 0
    • View Profile
Re: Function types and result
« Reply #1 on: May 01, 2017, 03:12:00 AM »
0
do not use "array of XXX" types as params or result type, thats bad practice in Pascal\Delphi.

Correct way in Pascal is to declare

type
  TMyArrType = array of array of XXX;

and than use it

function CheckTiles:TMyArrType;

and in all other places too.

Offline said3Topic starter

  • Jr. Member
  • **
  • Posts: 51
  • Activity:
    0%
  • Reputation Power: 1
  • said3 has no influence.
  • Respect: +20
  • Referrals: 2
    • View Profile
Re: Function types and result
« Reply #2 on: May 03, 2017, 09:43:51 AM »
0
I knew it was a silly thing. Thank you very much for your help.

I fixed it within seconds with that. :D

Tags: