SRL Archive - OSR Help

Type mismatch, 2D arrays


doom0791

2011-09-06 20:53:30

Maybe I'm just not understanding how to pass a 2D array into functions.


program new;
{$I SRL/SRL.scar}

var
tinColors, copColors : TIntegerArray;
tinMods, copMods : Array of Array[1..2] of Extended;
RockPoints : T2DPointArray;
i : integer;
mp : TPoint;


procedure setupVars;
begin
tinColors := [13750755, 13685220, 12764374, 13684963, 14408686];
copColors := [4621796, 10018559, 4555233, 6403839, 5611519];
end;

procedure debug;
begin
end;


procedure setupHSLmods;
//* HMod = Mods[i][1]
//* SMod = Mods[i][2]
var
HSLColor : Array[1..3] of Extended;
i : Integer;
begin
SetLength(tinMods, Length(tinColors));
for i := 0 to High(tinMods) do
begin
ColorToHSL(tinColors[i], HSLColor[1], HSLColor[2], HSLColor[3]);
tinMods[i][1] := HSLColor[1]/HSLColor[3];
tinMods[i][2] := HSLColor[2]/HSLColor[3];
end;

SetLength(copMods, Length(copColors));
for i:= 0 to High(copMods) do
begin
ColorToHSL(copColors[i], HSLColor[1], HSLColor[2], HSLColor[3]);
copMods[i][1] := HSLColor[1]/HSLColor[3];
copMods[i][2] := HSLColor[2]/HSLColor[3];
end;
end;

function FColorsSpiralTol(colors : TIntegerArray; mods : Array of Array of Extended; var TPA : TPointArray; tol : Integer) : Boolean;
var
i, CTS : Integer;
Temp : TPointArray;
H, S : Extended;
begin
TPA := [];
CTS := GetColorToleranceSpeed;
GetColorSpeed2Modifiers(H, S);
SetColorToleranceSpeed(2);
for i:= 0 to High(colors) do
begin
SetColorSpeed2Modifiers(mods[i][1], mods[i][2]);
FindColorsSpiralTolerance(MSCX, MSCY, Temp, colors[i], MSX1, MSY1, MSX2, MSY2, tol);
TPA := CombineTPA(Temp, TPA);
end;
if High(TPA) > 0 then
Result := true;
SetColorToleranceSpeed(CTS);
SetColorSpeed2Modifiers(H, S);
end;

function FindRock(colors : TIntegerArray; mods : Array of Array of Extended) : TPoint;
var
Pts : TPointArray;
TPAs : T2DPointArray;
begin
if FColorsSpiralTol(colors, mods, Pts, 5) then
begin
SortTPAFrom(Pts, Point(MSCX, MSCY));
TPAs := SplitTPA(Pts, 17);
SortATPAFrom(TPAs, Point(MSCX, MSCY));
Result := MiddleTPA(TPAs[High(TPAs)]);
end;
end;


function trackRock(midPoint : TPoint; colors : TIntegerArray) : TPointArray;
begin

end;

var
pts : tpointarray;

begin
SetupSRL;
setupVars;
setupHSLmods;
MarkTime(i);
FindRock(tinColors, tinMods); // Type Mismatch here <-
writeLn(intToStr(TimeFromMark(i)));
end.

I get type mismatch when calling either the FindRock function or the FColorsSpiralTol function and I'm almost positive it's because of my tinMods 2DArray of Extended.

Any suggestions on how to fix this, and maybe an explanation of why what I'm doing is wrong?

Thanks a ton!
-DooM0791

Coh3n

2011-09-06 21:42:35

tinMods and copMods are static arrays (you set the length in the declaration), take a way the [1..2] and problem solved (you'll have to set the length elsewhere).

Dgby714

2011-09-06 21:52:12

Or fix up his decl. You should make a type for it, makes things look much cleaner/clearer.

Flight

2011-09-06 21:56:33

From: Coh3n
tinMods and copMods are static arrays (you set the length in the declaration), take a way the [1..2] and problem solved (you'll have to set the length elsewhere).


That's kinda what I was thinking. I've only seen an example from BraK's forms work on how these arrays work. They don't seem very practical, just enough to organize slightly and, I think, save some lines of code. Are there many notable advantages to using these I should know about?

Coh3n

2011-09-06 22:10:38

From: Flight
That's kinda what I was thinking. I've only seen an example from BraK's forms work on how these arrays work. They don't seem very practical, just enough to organize slightly and, I think, save some lines of code. Are there many notable advantages to using these I should know about?
You mean 2D arrays? They're used A LOT in MSI. I think there's some 3D arrays used as well. They're very useful in certain situations. For example, MSI uses them to keep track of, say, the amount of fish caught for each player.

array of array of array of integer;
The number of fish caught per fishing spot (multiple fish per spot) per player.

NCDS

2011-09-06 22:36:37

From: Flight
That's kinda what I was thinking. I've only seen an example from BraK's forms work on how these arrays work. They don't seem very practical, just enough to organize slightly and, I think, save some lines of code. Are there many notable advantages to using these I should know about?


Yeah man, Arrays in general are key to what we do really. I've always loved them.

doom0791

2011-09-06 23:04:37

From: Coh3n
tinMods and copMods are static arrays (you set the length in the declaration), take a way the [1..2] and problem solved (you'll have to set the length elsewhere).


That worked beautifully, thank you!

I remember from my Computer Science class that in C++ it's better to pass in a pointer instead of a variable for large arrays to save time because it doesn't have to copy the entire array over again. Is this also the case for Pascal?

From: dgby714
Or fix up his decl. You should make a type for it, makes things look much cleaner/clearer.


I'll do that instead of using 2D arrays - It's much simpler that way, I just hadn't thought of it :P.

Thank you all!
-DooM

Dgby714

2011-09-06 23:20:56

From: doom0791
I remember from my Computer Science class that in C++ it's better to pass in a pointer instead of a variable for large arrays to save time because it doesn't have to copy the entire array over again. Is this also the case for Pascal?


PascalScript doesn't support Pointers in scripts. Tho internally I believe it does that already.