SRL Archive - OSR Help

Listing colours


Richard

2011-01-14 21:45:00

I knocked up a script in about half an hour that is meant to display all the different colours in the area of the client that I hard code. Initially I left it to feed all the colours into the debug box, but that was a) quite inefficient and b) extremely useless as looking through all those colours would have taken forever. To counter this, I made it search through the array I created to make sure there was no repetitions in colours, but it only displays the very top left colour of the area selected. I'm guessing the problem lies in the TIA search. Code:
program ListColours;

type
TPixel = record
Point: TPoint;
Colour: Integer;
end;

Var
Pixels: Array of TPixel;
Colours: TIntegerArray;
x, y, i, ii: integer;

begin
SetArrayLength(Pixels, 26*32 + 1)
for x := 5 to 26 do //these are the parameters
for y := 5 to 32 do //of the area that I'm searching
begin
With Pixels[x*y] do
begin
Point.x := x //ignore these for now
Point.y := y //they'll have future use
Colour := GetColor(x, y);
end;
end;
SetArrayLength(Colours, 1);
for i := 25 to High(Pixels) do
for ii := 0 to High(Colours) do
if Pixels[i].Colour <> Colours[ii] then
begin
SetArrayLength(Colours, High(colours) + 1);
Colours[ii] := Pixels[i].Colour;
end;
for i := 0 to High(Colours) do
WriteLN(IntToStr(Colours[i]));
end.

Heysus

2011-01-19 22:41:59

Change the last part to this:
  SetArrayLength(Colours, 1);
for i := 25 to High(Pixels) do
for ii := 0 to High(Colours) do
begin
if Pixels[i].Colour = Colours[ii] then
break;

if ii = High(Colours) then
begin
SetArrayLength(Colours, High(colours) + 1);
Colours[ii] := Pixels[i].Colour;
end;
end;


Also, theres some functions in wizzyPlugin that might help you
function InIntArray(a: TIntegerArray; Number: Integer): Boolean;
procedure ClearSameIntegers(var a: TIntegerArray);

Richard

2011-01-31 19:23:38

From: Heysus
Change the last part to this:
  SetArrayLength(Colours, 1);
for i := 25 to High(Pixels) do
for ii := 0 to High(Colours) do
begin
if Pixels[i].Colour = Colours[ii] then
break;

if ii = High(Colours) then
begin
SetArrayLength(Colours, High(colours) + 1);
Colours[ii] := Pixels[i].Colour;
end;
end;


Also, theres some functions in wizzyPlugin that might help you
function InIntArray(a: TIntegerArray; Number: Integer): Boolean;
procedure ClearSameIntegers(var a: TIntegerArray);


Thank you.

Sorry I didn't reply previously, I hadn't seen your post, and only just checked to see whether this had been seen to.