SRL Archive - OSR Help

Sorting tiles


KingKong

2011-02-04 01:35:30

I have this situation where i get a bunch of tiles and store them in an array. I then have to delete the duplicates from this array, how would i go about doing it efficiently? I tried 'if tile in array'(this isn't the exact syntax), but it doesn't work.

TomTuff

2011-02-04 01:41:07

When you say it didn't work, did it just take forever? Or did it literally provide you no good results?

KingKong

2011-02-04 01:46:43

It said type mismatch. (The 'in' method works if i try to search for integers in a variantarray, but variant doesn't take TTiles or TPoints)

Edit: Woot! 500 posts!

kitchenrange

2011-02-04 01:51:10

Check for Fakawi's thread where he asks for a function that removes duplicates from an array.

Somone posted a nice one.

KingKong

2011-02-04 02:01:41

Post the link?plz?

kitchenrange

2011-02-04 02:08:18

Sorry its in members forum. Doubt it will be a problem to share the function though.

Complete credits to Frement.

function array_unique(src: TVariantArray): TVariantArray;
var I, O, E: Integer;
Skip: Boolean;
begin
SetArrayLength(Result, 1);
Skip := False;
E := 0;
for I := 0 to High(src) do begin
for O := 0 to High(Result) do begin
if (Result[O] = src[I]) then begin
Skip := True;
break;
end;
end;
if not (Skip) then begin
SetArrayLength(Result, E+1);
Result[E] := src[I];
Inc(E);
end;
Skip := False;
end;
end;

KingKong

2011-02-04 02:15:13

^It doesn't work, since variant can't take ttiles/tpoints :(

Rich

2011-02-04 02:49:36

^ Then couldn't you just set the var as a TTileArray?

**BANNED The Man

2011-02-04 02:53:30

Umm surely you just change TVariant to TTile…

Edit: gah mobile internet give ninjaa advantage xD ^
-Boom

KingKong

2011-02-04 03:01:49

From: Rich
^ Then couldn't you just set the var as a TTileArray?


:duh: thanks for pointing it out.