SRL Archive - SRL Archives

Timing.scar


TRiLeZ

2009-08-29 06:30:38


{*******************************************************************************
function WaitColors(var FoundColor: Integer; X, Y: Integer; Color: TIntegerArray; Tol, MaxTime: Integer): Boolean;
By: TRiLeZ
Description: Waits for multiple colours at (x, y) with tolerance, returns true if found one colour.
*******************************************************************************}
function WaitColors(var FoundColor: Integer; X, Y: Integer; Color: TIntegerArray; Tol, MaxTime: Integer): Boolean;
var
Time, I: Integer;
begin
Time := GetSystemTime + MaxTime;
while (GetSystemTime < Time) do
begin
for I := 0 to High(Color) do
begin
if (GetSystemTime > Time) then Exit;
if SimilarColors(GetColor(X, Y), Color[i], Tol) then
begin
FoundColor := GetColor(X, Y);
Result := True;
Exit;
end;
Wait(1 + Random(2));
end;
end;
end;


{*******************************************************************************
function WaitFindColors(var X, Y, FoundColor: Integer; Color: TIntegerArray; x1, y1, x2, y2, Tol, MaxTime: Integer): Boolean;
By: TRiLeZ
Description: Waits for multiple colours in an area with tolerance, returns true if found one colour.
*******************************************************************************}
function WaitFindColors(var X, Y, FoundColor: Integer; Color: TIntegerArray; x1, y1, x2, y2, Tol, MaxTime: Integer): Boolean;
var
Time, I: Integer;
begin
Result := False;
Time := GetSystemTime + MaxTime;
while (GetSystemTime < Time) do
begin
for I := 0 to High(Color) do
begin
if (GetSystemTime > Time) then Exit;
if FindColorTolerance(X, Y, Color[i], x1, y1, x2, y2, Tol) then
begin
FoundColor := GetColor(X, Y);
Result := True;
Exit;
end;
Wait(2 + Random(4));
end;
end;
end;


{*******************************************************************************
function WaitFindColorsSpiral(var x, y, FoundColor: integer; Color: TIntegerArray; x1, y1, x2, y2, Tol, MaxTime: integer): Boolean;
By: TRiLeZ
Description: Searches for multiple colours in an area with tolerance using FindColorSpiralTolerance, returns true if found one colour.
*******************************************************************************}
function WaitFindColorsSpiral(var x, y, FoundColor: integer; Color: TIntegerArray; x1, y1, x2, y2, Tol, MaxTime: integer): Boolean;
var
Time, I: Integer;
begin
Result := False;
Time := GetSystemTime + MaxTime;
while (GetSystemTime < Time) do
begin
for I := 0 to High(Color) do
begin
if (GetSystemTime > Time) then Exit;
if (FindColorSpiralTolerance(X, Y, Color[i], x1, y1, x2, y2, Tol)) then
begin
FoundColor := GetColor(X, Y);
Result := True;
Exit;
end;
Wait(2 + Random(4));
end;
end;
end;

If your thinking "Why not replace WaitColor, WaitFindColor and WaitFindColorSpiral" then heres your answer: it will break some scripts.

Tell me what to think and If youll include them.

They could be called WaitColorMulti, WaitFindColorMulti and WaitFindColorMultiSpiral if you think those are a more suitable name.

Naum

2009-08-29 12:49:25

Use High(); instead of Length();. And if you want to use Length(); subtract one of the end ;)

TRiLeZ

2009-08-29 14:08:26

Oh yes I forgot about using High. I edited it in :)

Sir R. M8gic1an

2009-08-29 14:39:41

Spiral won't be included, not much point in it.

And the only difference between these and the ones currently existing is the possibility of using multiple colors.

Can you think of any specific use for this, other than it's cool?

considering that the other already allow for tolerance, I guess you'd be thinking there'd be a huge difference in colors to show up in one same place. Do you have any specific case in mind?

~RM

TRiLeZ

2009-08-29 20:54:36

Case 1: When you click, either theirs a red cross or a yellow cross so this could wait for one and give off if it was yellow or red.
Case 2: If you are cooking something, it could burn or be nicely cooked.

mormonman

2009-08-29 20:56:23

Case 1: Already in the include.
Case 2: Check with dtms.

TRiLeZ

2009-08-29 21:00:00

Whats the function for case 1?

mormonman

2009-08-29 21:01:47

[php]{*******************************************************************************
Function DidClick(Red: Boolean; Time: integer);
By: Rasta Magician
Description: Checks for the X after a click, Times Out after Time.
*******************************************************************************}[/php]

Rich

2009-08-29 21:20:39

You could using it for finding trees which take time to re-spawn…

Sir R. M8gic1an

2009-09-08 15:30:12

I don't like the idea of searching for multiple colors, because in the end you don't know which one popped up and you'd have to search for it again, therefore being inneficient.

As for the case of the fish being nicely cooked or burnt, you'd probably just do CountDTM at the end.

However, i am considering WaitColorGone , which would return true when a color dissapears. (raw fish color gone, Tree trunk color gone) , but then again for the tree you could just WaitColor(TreeColor)

~RM

TRiLeZ

2009-09-09 01:15:10

The functions return the colour that was found.
As for WaitColorGone, I will make that function if your not already making it.