SRL Archive - SRL Archives

4 Additions to Color.scar


TRiLeZ

2009-07-23 13:55:22


{*******************************************************************************
function WaitForColor(x, y, Color, TimeOut: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color at a point with a timeout.
*******************************************************************************}
function WaitForColor(x, y, Color, TimeOut: Integer): Boolean;
var
Start: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until GetColor(x, y) = Color;
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;

{*******************************************************************************
function WaitForColorTol(x, y, Color, TimeOut, Tol: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color at a point with a timeout and tolerance.
*******************************************************************************}
function WaitForColorTol(x, y, Color, TimeOut, Tol: Integer): Boolean;
var
Start, cx, cy: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until FindColorTolerance(cx, cy, Color, x, y, x, y, Tol);
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;
 
{*******************************************************************************
function WaitForColorIn(xs, ys, xe, ye, Color, TimeOut: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color in a box with a timeout.
*******************************************************************************}
function WaitForColorIn(xs, ys, xe, ye, Color, TimeOut: Integer): Boolean;
var
Start, cx, cy: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until FindColor(cx, cy, Color, xs, ys, xe, ye);
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;

{*******************************************************************************
function WaitForColorTolIn(xs, ys, xe, ye, Color, TimeOut, Tol: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color in a box with a timeout and tolerance.
*******************************************************************************}
function WaitForColorTolIn(xs, ys, xe, ye, Color, TimeOut, Tol: Integer): Boolean;
var
Start, cx, cy: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until FindColorTolerance(cx, cy, Color, xs, ys, xe, ye, Tol);
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;

Tell me if you like my functions and if they'll be added in SRL.

ShowerThoughts

2009-07-23 14:03:22

Positive.

Naum

2009-07-23 14:08:41

From: TRiLeZ

{*******************************************************************************
function WaitForColor(x, y, Color, TimeOut: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color at a point with a timeout.
*******************************************************************************}
function WaitForColor(x, y, Color, TimeOut: Integer): Boolean;
var
Start: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until GetColor(x, y) = Color;
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;

{*******************************************************************************
function WaitForColorTol(x, y, Color, TimeOut, Tol: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color at a point with a timeout and tolerance.
*******************************************************************************}
function WaitForColorTol(x, y, Color, TimeOut, Tol: Integer): Boolean;
var
Start, cx, cy: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until FindColorTolerance(cx, cy, Color, x, y, x, y, Tol);
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;
 
{*******************************************************************************
function WaitForColorIn(xs, ys, xe, ye, Color, TimeOut: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color in a box with a timeout.
*******************************************************************************}
function WaitForColorIn(xs, ys, xe, ye, Color, TimeOut: Integer): Boolean;
var
Start, cx, cy: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until FindColor(cx, cy, Color, xs, ys, xe, ye);
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;

{*******************************************************************************
function WaitForColorTolIn(xs, ys, xe, ye, Color, TimeOut, Tol: Integer): Boolean;
by: TRiLeZ
Description: Waits for a color in a box with a timeout and tolerance.
*******************************************************************************}
function WaitForColorTolIn(xs, ys, xe, ye, Color, TimeOut, Tol: Integer): Boolean;
var
Start, cx, cy: Integer;
begin
MarkTime(Start);
repeat
Wait(1);
if (TimeFromMark(Start) >= TimeOut) then Exit;;
until FindColorTolerance(cx, cy, Color, xs, ys, xe, ye, Tol);
if (TimeFromMark(Start) < Timeout) then Result:= True;
end;

Tell me if you like my functions and if they'll be added in SRL.



Half of what you have made is a variant of the functions already made in SRL. Furthermore, would you mind telling me the usage of waiting to get one pixel of color? Wouldn't it be wiser to 'FindColTol' it?

ShowerThoughts

2009-07-23 14:15:06

For example the bank screen uses now text finding but what the heck, you can wait 1000 before a brownish pixels comes up and tada bankscreen detected ;).

It is useful.

Naum

2009-07-23 14:17:48

From: Hermen
For example the bank screen uses now text finding but what the heck, you can wait 1000 before a brownish pixels comes up and tada bankscreen detected ;).

It is useful.


Couldn't you do WaitColor instead?
WaitColor also has tolerance, and is already in SRL ;)

TRiLeZ

2009-07-23 14:18:50

From: NaumanAkhlaQ
Half of what you have made is a variant of the functions already made in SRL. Furthermore, would you mind telling me the usage of waiting to get one pixel of color? Wouldn't it be wiser to 'FindColTol' it?


If you click something and it takes a number of seconds for something to appear, the script would wait for until the color pops up onto the screen.

For example, clicking on a Lecture takes 1.5 - 3 seconds to appear so it will wait for the interface to appear and is faster than using one constant wait time.

Also, aren't the color finding function built into SCAR and not made by SRL?

ShowerThoughts

2009-07-23 14:18:57

I thought he made new ones, NOEZ.

Naum

2009-07-23 14:22:24

From: TRiLeZ
If you click something and it takes a number of seconds for something to appear, the script would wait for until the color pops up onto the screen.

For example, clicking on a Lecture takes 1.5 - 3 seconds to appear so it will wait for the interface to appear and is faster than using one constant wait time.

Also, aren't the color finding function built into SCAR and not made by SRL?


{*******************************************************************************
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
By: Rasta Magician
Description: Waits for a color at (x, y) with tolerance Tol, returns true if found
*******************************************************************************}
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
var
Time: integer;
begin
Result := False;
Time := GetSystemTime + MaxTime;
while Time < GetSystemTime do
if SimilarColors(GetColor(x, y), Color, Tol) then
begin
Result := true;
exit;
end;
end;

(h)

TRiLeZ

2009-07-23 14:29:50

From: NaumanAkhlaQ
{*******************************************************************************
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
By: Rasta Magician
Description: Waits for a color at (x, y) with tolerance Tol, returns true if found
*******************************************************************************}
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
var
Time: integer;
begin
Result := False;
Time := GetSystemTime + MaxTime;
while Time < GetSystemTime do
if SimilarColors(GetColor(x, y), Color, Tol) then
begin
Result := true;
exit;
end;
end;

(h)


I never saw that function before…
What about WaitForColorIn and WaitForColorTolIn?

TRiLeZ

2009-07-23 15:00:38

I was testing out WaitColor and it dosnt seem to work for me =/
I tested with my function and it worked perfectly.

Sir R. M8gic1an

2009-07-23 16:33:16


// * Function WaitOptionMulti(S: TStringArray; Time: Integer): Boolean; // By Marpis, N1ke! & Rasta Magician
// * Function WaitOption(S: String; Time: Integer): Boolean; // By N1ke!
// * Function WaitUptextMulti(S: TStringArray; Time: integer): Boolean; // By Marpis & N1ke!
// * Function WaitUptext(S: String; Time: Integer): Boolean; // By N1ke!
// * Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean; // By Rasta Magician
// * Function WaitFindColor(var x, y: integer; x1, y1, x2, y2, Color, Tol, MaxTime: integer): boolean; // By Rasta Magician
// * Function WaitFindColorSpiral(var x, y: integer; x1, y1, x2, y2, Color, Tol, MaxTime: integer): boolean; // By Rasta Magician
// * Function WaitColorCount(x1, y1, x2, y2, Color, Tol, MinCount, MaxCount, MaxTime: integer):boolean; // By Rasta Magician
// * Function WaitFunc(Func: Function: boolean; MaxTime: integer): boolean; // By Rasta Magician



{*******************************************************************************
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
By: Rasta Magician
Description: Waits for a color at (x, y) with tolerance Tol, returns true if found
*******************************************************************************}
Function WaitColor(x, y, Color, Tol, MaxTime: integer): Boolean;
var
Time: integer;
begin
Result := False;
Time := GetSystemTime + MaxTime;
while Time < GetSystemTime do
if SimilarColors(GetColor(x, y), Color, Tol) then
begin
Result := true;
exit;
end;
end;

{*******************************************************************************
Function WaitFindColor(var x, y: integer; Color, Tol, x1, y1, x2, y2, MaxTime: integer): Boolean;
By: Rasta Magician
Description: Waits for a color at (x1, y1, x2, y2) with tolerance Tol, returns true if found, coords returned to (x, y)
*******************************************************************************}
Function WaitFindColor(var x, y: integer; Color, x1, y1, x2, y2, Tol, MaxTime: integer): Boolean;
var
Time: integer;
begin
Result := False;
Time := GetSystemTime + MaxTime;
While GetSystemTime < Time do
if FindColorTolerance(x, y, Color, x1, y1, x2, y2, Tol) then
begin
Result := true;
exit;
end;
end;

Therefore no, they won't be added to SRL as they already exist in SRL and are more efficient.

Also, you might want to know that if you are looking for a color in just one place it is faster to do GetColor than findColor(x1, y1, x1, y1) as you did.

~RM