SRL Archive - OSR Help

Wait Color Box func help


Le Jingle

2012-08-13 22:23:16

Hi, this post is: Me @query T2DIntegerArray's.

*** This was a function designed by Runaway ***

He seems to be inactive lately :< so I thought the community might be more responsive

I run into an 'Out of Range' error (posted in image below)
[—The //0 was the original code, but my 1 produces the same error—]

I'm having difficulty understanding if the MaxA isn't compatible with the for to do loop in the T2DIntegerArray.. or if I'm missing out on something obvious.

Here's the test script I'm using;



{$i srl/srl.simba}

function WaitColorBox(WaitTime: Integer; Color, Min, Tol: TIntegerArray; Box: TBoxArray; Strict: Boolean): Boolean;
var
c: T2DIntegerArray;
TPA: TPointArray;
Temp: TIntegerArray;
hMax, hTemp, Count, h, hh, t, i: Integer;
hColor, hMin, hTol, hBox: Integer;
begin
if not LoggedIn then
Exit;
Result := False;
hColor := High(Color); // All of this hXXX bullshiz is just to allow for a special feature that
hMin := High(Min); // I've added into this. You can enter 2 search boxes and 1 of everything else
hTol := High(Tol); // and the function will search for the specified color, with the min and tol
hBox := High(Box); // values in both search boxes. It can be done vice versa as well.
Temp := [hColor, hMin, hTol, hBox];
hTemp := High(Temp);
hMax := MaxA(Temp);
SetLength(c, hMax + 1);
for h := 0 to hTemp do
begin
for hh := 0 to hMax do
begin
if (Temp[h] < 1) then
c[hh][h] := 1//0
else
c[hh][h] := hh;
end;
end;
MarkTime(t);
repeat
Count := 0;
for i := 0 to hMax do
begin
FindColorsTolerance(TPA, Color[c[i][0]], Box[c[i][3]].x1, Box[c[i][3]].y1, Box[c[i][3]].x2, Box[c[i][3]].y2, Tol[c[i][2]]);
if (Length(TPA) > Min[c[i][1]]) then
Inc(Count);
end;
if Strict then
begin
if (Count >= (hColor + 1)) then
begin
Result := True;
Exit;
end;
end else
begin
if (Count > 0) then
begin
Result := True;
Exit;
end;
end;
Wait(100+Random(50));
until(TimeFromMark(t) > WaitTime);
writeln('Reached the end of the "Wait Color Box" Function.');
end;

var
aBOX: TBoxArray;

begin
SetupSRL;
ActivateClient;
setlength(aiobox, 2);
aBox[0] := InvBox(1);
aBox[1] := InvBox(2);
if WaitColorBox(100, [1710098], [25], [15], [abox[0],abox[1]], true) then
writeln('true')
else
writeln('false');
end.


Edit : this was from him via a script (vcgrocktails), for the additive information. Extra info : I'm trying to hunk a wide variety cooking guild cooker,

Nebula

2012-08-13 23:43:55

Howbout using WaitFuncEx with FindColorsTolerance?

Olly

2012-08-17 08:05:13

Why not use something like this?

Function Colorbox : boolean;
begin
Result := CountColorTolerance(2104079, 315, 348, 339, 373 , 20) > 100;
end;

If WaitFunc(@ColorBox, 50, 1000) Then
Writeln('yey');
else
Writlen('noooo');

Runaway

2012-08-17 12:47:26

Hey Jingle,

The out of range error is because the length of the final array is never set. While it's looping through the whole c[hh][h] business, the [h] doesn't have a specified length so Simba refuses to allow a value to be stored there. If you write out the T2DIntegerArray like this:


array of array of Integer

you can see that there are 2 arrays. Since the length of the arrays aren't set when declaring the vars (array[0..3]), their lengths must be declared within the function via SetLength(). I had only set the length of the first array when I sent you this code, so that's why it wasn't working.

Here's the fixed (and a tad shortened) version:


program new;
{$i srl/srl.simba}

function WaitColorBox(WaitTime: Integer; Color, Min, Tol: TIntegerArray; Box: TBoxArray; Strict: Boolean): Boolean;
var
c: T2DIntegerArray;
TPA: TPointArray;
Temp: TIntegerArray;
hColor, hMax, hTemp, Count, h, hh, t, i: Integer;
begin
if not LoggedIn then
Exit;
Result := False;
hColor := High(Color);
Temp := [hColor, High(Min), High(Tol), High(Box)];
hTemp := High(Temp);
hMax := MaxA(Temp);
SetLength(c, hMax + 1);
for h := 0 to hTemp do
begin
for hh := 0 to hMax do
begin
SetLength(c[hh], hTemp + 1); // Right herr
if (Temp[h] < 1) then
c[hh][h] := 0
else
c[hh][h] := hh;
end;
end;
MarkTime(t);
repeat
Count := 0;
for i := 0 to hMax do
begin
FindColorsTolerance(TPA, Color[c[i][0]], Box[c[i][3]].x1, Box[c[i][3]].y1, Box[c[i][3]].x2, Box[c[i][3]].y2, Tol[c[i][2]]);
if (Length(TPA) > Min[c[i][1]]) then
Inc(Count);
end;
if Strict then
begin
if (Count >= (hColor + 1)) then
Result := True;
end else
begin
if (Count > 0) then
Result := True;
end;
if Result then
Exit;
Wait(100+Random(50));
until(TimeFromMark(t) > WaitTime);
writeln('Reached the end of the "Wait Color Box" Function.');
end;

var
aBox: TBoxArray;

begin
SetupSRL;
ActivateClient;
setlength(aBox, 2); // You had it set to aiobox before :o
aBox[0] := InvBox(1);
aBox[1] := InvBox(2);
if WaitColorBox(100, [1710098], [25], [15], [aBox[0], aBox[1]], true) then
writeln('true')
else
writeln('false');
end.

Good luck :)

Le Jingle

2012-08-17 13:49:08

Ahh, you teach me a new thing everytime. Not even joking ^.^

I was getting stuck and thought the problem was using the tolerance array, which I'm still figuring out; but I think if you only put one tolerance in the array, it will use that for both colors(?). (I was trying to limit the tolerance array, as well as the min, and then messing with the TBoxArray >.<)

Thanks for the amazing help, again! (sorry for aio :<)

Runaway

2012-08-17 17:26:28

From: Le Jingle
Ahh, you teach me a new thing everytime. Not even joking ^.^

I was getting stuck and thought the problem was using the tolerance array, which I'm still figuring out; but I think if you only put one tolerance in the array, it will use that for both colors(?). (I was trying to limit the tolerance array, as well as the min, and then messing with the TBoxArray >.<)

Thanks for the amazing help, again! (sorry for aio :<)


No problem! I'm just doing my part, that's all ;)

I'll give you a quick little overview of exactly what the function is doing. You're right about this: "but I think if you only put one tolerance in the array, it will use that for both colors", although it goes a little further than that. I'll just use what you posted as an example.

I don't think explaining it with words is the best way to go about this, so I'm just going to give examples and the results.


WaitColorBox(100, [1710098], [25], [15], [aBox[0]], True);
// ^ Searches the specified box for the color/count/tol and returns true if found.

WaitColorBox(100, [1710098, 1859157], [25], [15], [aBox[0]], True);
// ^ Searches the specified box for both colors with the same count/tol and returns
// true if both are found.

WaitColorBox(100, [1710098, 1859157], [25], [15, 18], [aBox[0]], True);
// ^ Searches the specified box for both colors with their respective tols (but the
// same count) and returns true if both are found.

WaitColorBox(100, [1710098], [25], [15], [aBox[0], aBox[1]], True);
// ^ Searches both boxes for the color/count/tol and returns true if both are found.

WaitColorBox(100, [1710098, 1859157], [25], [15], [aBox[0], aBox[1]], True);
// ^ Searches each box for the respective color (1710098 in aBox[0], 1859157 in aBox[1])
// with the same count/tol and returns true if both are found.

The last parameter, that I've called 'strict', is very important. Setting strict to true will require everything to be found to return true, whereas setting it to false only requires a single color/count to be found to return true.


WaitColorBox(100, [1710098], [25], [15], [aBox[0], aBox[1]], True);
// ^ Will search both boxes for the specified color/count and only return true if the
// color/count is found in both boxes.

WaitColorBox(100, [1710098], [25], [15], [aBox[0], aBox[1]], False);
// ^ Same as above, except it will return true if the color/count is found in either of
// the boxes.

I don't know how to explain it any better :pinch: Just make sure you don't use uneven amounts of parameters (2 colors with 3 tols, stuff like that). I don't know how Simba will handle that, but it definitely won't work! Some people would say that this function is pointless because it can be easily done in other ways, for example:


if WaitColorWhatever(100, 1710098, 25, 15, aBox[0]) and WaitColorWhatever(100, 1859157, 25, 18, aBox[1]) then

// is the same as:

if WaitColorBox(100, [1710098, 1859157], [25], [15, 18], [aBox[0], aBox[1]], True) then

WaitColorWhatever would have a lot less code and things would look more simple but… where's the fun in that! Striving for complexity and consolidation is striving for success in my book :p Well this sort of turned into an odd pep-talk or something so I'm going to wrap it up here before I really veer off course. Anyways, If you need any help feel free to shoot me a PM. Or you can always just post in the help section and I'll find it eventually :sasmokin:

CephaXz

2012-08-17 17:32:02

^ That is BEAST!

Le Jingle

2012-08-17 17:48:37

Ahh okay yes those examples make much more sense now. And I sort of got the idea that the use of strict was requiring more of the function to be found to result the whole of the function true, I was weary of that and confirmation on that too makes more sense. All in all I suppose I'll have to study over the specifics of functions alike WaitColorBox, FindColoredAreaMulti, FindTPointCluster, etc. Your functions are neat too, as they do condense a lot of actions into easier to read code, with the hefty complexity added to it. Thanks for the lesson+Pep talk! ^^