SRL Archive - SRL Archives

Need function: OptionCount(Texts: TStringArray): integer


marpis

2009-08-06 22:49:19

I dont know alot about text finding, so i thought someone could maybe write me this function? I already checked that 1 row is about 15.4 pixels high ^^

It'd work like this:
There are 3 items in the ground. I right click there, and call function
Writeln('There are '+IntToStr(OptionCount(['Take']))+' items in the ground!');
this should print text
"There are 3 items in the ground!"

Shuttleu

2009-08-06 23:01:08

i shall make it (as long as no one else does first…)

~shut

EDIT: sorry i had to go out
but try this
function OptionCount(Text: string): Integer;
var
TP: TPoint;
xx: Integer;
begin
while IsTextInAreaEx(xx, 0, 764, 502, TP.x, TP.y, Text, 3, UpChars, false, false, 0, 0, 4231423) do
begin
Inc(Result);
xx:= TP.x+15;
end;
end;
i havent managed to test it as i am running linux but it should work

Smarter Child

2009-08-07 03:55:00

I recall that he wanted a TStringArray but, i suppose you could make a seperate array, using i etc.
If this works, I don't see why it wouldn't be in SRL :).

mormonman

2009-08-07 06:56:33

From: Smarter Child
I recall that he wanted a TStringArray but, i suppose you could make a seperate array, using i etc.
If this works, I don't see why it wouldn't be in SRL :).


'tis easy to do…


function OptionCount(Texts: TStringArray): Integer;
var
TP: TPoint;
xx, i: Integer;
begin
for i := 0 to High(Texts) do
while IsTextInAreaEx(xx, 0, 764, 502, TP.x, TP.y, Texts[i], 3, UpChars, false, false, 0, 0, 4231423) do
begin
Inc(Result);
xx:= TP.x+15;
end;
end;

I don't think that is exactly what marpis is looking for…

Edit: Looked into it…

function CountOptions(Texts: TStringArray): Integer;
var
B: TBox;
TPA, TextTPA: TPointArray;
aTPA: T2DPointArray;
I, C, H, HH, ii, L: Integer;
P: TPoint;
Occurances: array [0..2] of TPointArray;
begin
GetClientDimensions(B.X2, B.Y2);
B.X1 := 0;
B.Y1 := 0;
SetLength(aTPA, 2);
FindColorsTolerance(aTPA[0], 4409686, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(aTPA[1], 4016722, B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := MergeATPA(aTPA);
SetLength(aTPA, 0);
If Length(TPA) < 10 Then
Exit;
B.X2 := 0;
B.Y2 := 0;

P := TPA[0];
H := High(TPA);
Dec(H);
For I := 0 To H Do
If TPA[i].X = TPA[I+1].X - 1 Then
Begin
If C > 5 Then
Begin
B.X1 := P.X;
B.Y1 := P.Y;
Break;
End Else
C := C + 1;
End
Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;
InvertTPA(TPA);
C := 0;
P := TPA[0];
H := High(TPA);
Dec(H);
For I := 0 To H Do
If TPA[i].X = TPA[I+1].X + 1 Then
Begin
If C > 5 Then
Begin
B.X2 := P.X;
B.Y2 := P.Y;
Break;
End Else
C := C + 1;
End Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;

TPA := [];
begin
FindColorsTolerance(Occurances[0], 1845035, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(Occurances[1], clBlack, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(Occurances[2], 6121839, B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := MergeATPA(Occurances);

ClearDoubleTPA(TPA);
TPA := ReturnPointsNotInTPA(TPA, B);
end;
if High(TPA) < 1 then TPA := MergeATPA(Occurances);
aTPA := SplitTPAEx(TPA, 7, 1);
SortATPAFromFirstPoint(aTPA, Point(B.x1, B.y1));

H := High(Texts);
L := High(aTPA);

For I :=0 To H do
begin
TextTPA := LoadTextTPA(Texts[i], UpChars, HH);
for ii := 0 to L do
If FindTextTPAInTPA(HH, TextTPA, aTPA[ii], TPA) Then
Begin
Inc(Result);
End;
end;

if (Result > 0) then Exit;
MMouse(B.X1 - 50, B.Y1 - 50, 40, B.Y2 - B.Y1);
Wait(200 + Random(100));
end;

marpis

2009-08-07 17:25:09


For I :=0 To H do
begin
TextTPA := LoadTextTPA(Texts[i], UpChars, HH);
for ii := 0 to L do
If FindTextTPAInTPA(HH, TextTPA, aTPA[ii], TPA) Then
Begin
Inc(Result);
Exit;
End;
end;

I dont think you really want to Exit there?

mormonman

2009-08-07 18:17:26

Oops, lol my bad.
Test the fixed one now.

marpis

2009-08-08 18:12:20

mormonman, thats not what i meant ^^
I meant that if there are 4 items in the ground, then there is 4 times text "Take" in the optionbox. So CountOptions(['Take']) returns 4 in this case.

edit: i think i try this on my own too

Sir R. M8gic1an

2009-08-08 18:32:20

Choose Option
– Examine CowHide
– Take Cowhide
– Examine Beef
– Take Beef
– Examine Bones
– Take bones


basically what you are looking for is a function that will count the bolded parts, right?

~RM

mormonman

2009-08-09 10:21:03

From: marpis
mormonman, thats not what i meant ^^
I meant that if there are 4 items in the ground, then there is 4 times text "Take" in the optionbox. So CountOptions(['Take']) returns 4 in this case.

edit: i think i try this on my own too


mine does exactly that, maybe you should at least test it…

marpis

2009-08-09 15:15:26

From: mormonman
mine does exactly that, maybe you should at least test it…


It returns 0 all the time, plus it moves the mouse which is not good

Shuttleu

2009-08-11 20:29:00

did you try mine?

~shut

EDIT: just tested it and found a mistake i made
here is a perfetly workin one :)
function OptionCount(Text: string): Integer;
var
TP: TPoint;
yy: Integer;
begin
while IsTextInAreaEx(0, yy, 764, 502, TP.x, TP.y, Text, 3, UpChars, false, false, 0, 0, 9812166) do
begin
Inc(Result);
yy:= TP.y+15;
end;
end;

marpis

2009-08-12 20:22:34

Well, i made my own one, its working too:

function CountOptions(Texts: TStringArray): Integer;
var
B: TBox;
TPA, TextTPA: TPointArray;
aTPA: T2DPointArray;
I, C, H, HH, ii: Integer;
P: TPoint;
Occurances: array [0..2] of TPointArray;
SmallBoxes: TBoxArray;
begin
GetClientDimensions(B.X2, B.Y2);
B.X1 := 0;
B.Y1 := 0;
SetLength(aTPA, 2);
FindColorsTolerance(aTPA[0], 4409686, B.X1, B.Y1, B.X2, B.Y2, 0);
FindColorsTolerance(aTPA[1], 4016722, B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := MergeATPA(aTPA);
SetLength(aTPA, 0);
If Length(TPA) < 10 Then
Exit;
B.X2 := 0;
B.Y2 := 0;

P := TPA[0];
H := High(TPA);
Dec(H);
For I := 0 To H Do
If TPA[i].X = TPA[I+1].X - 1 Then
Begin
If C > 5 Then
Begin
B.X1 := P.X;
B.Y1 := P.Y;
Break;
End Else
C := C + 1;
End
Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;
InvertTPA(TPA);
C := 0;
P := TPA[0];
H := High(TPA);
Dec(H);
For I := 0 To H Do
If TPA[i].X = TPA[I+1].X + 1 Then
Begin
If C > 5 Then
Begin
B.X2 := P.X;
B.Y2 := P.Y;
Break;
End Else
C := C + 1;
End Else
Begin
P := TPA[I + 1];
C := 0;
End;
If I = Length(TPA) Then
Begin
WriteLn('Choose Option Menu Getting Failed');
Exit;
End;

///////////////////////////////////////
SetLength(SmallBoxes, (B.y2 - B.y1)/15);
for i := 0 to High(SmallBoxes) do
begin
SmallBoxes[i].x1 := B.x1;
SmallBoxes[i].y1 := B.y1 + i * 15 + 3;
SmallBoxes[i].x2 := B.x2;
SmallBoxes[i].y2 := B.y1 + (i + 1) * 15 + 3;
end;

for ii := 0 to High(Texts) do
begin
TextTPA := LoadTextTPA(Texts[ii], UpChars, HH);
for i := 0 to High(SmallBoxes) do
begin
FindColorsTolerance(Occurances[0], 1845035, SmallBoxes[i].X1, SmallBoxes[i].Y1 - 5, SmallBoxes[i].X2, SmallBoxes[i].Y2 + 5, 0);
FindColorsTolerance(Occurances[1], clBlack, SmallBoxes[i].X1, SmallBoxes[i].Y1 - 5, SmallBoxes[i].X2, SmallBoxes[i].Y2 + 5, 0);
FindColorsTolerance(Occurances[2], 6121839, SmallBoxes[i].X1, SmallBoxes[i].Y1 - 5, SmallBoxes[i].X2, SmallBoxes[i].Y2 + 5, 0);
TPA := MergeATPA(Occurances);

ClearDoubleTPA(TPA);
TPA := ReturnPointsNotInTPA(TPA, SmallBoxes[i]);
if High(TPA) < 1 then TPA := MergeATPA(Occurances);
if FindTextTPAInTPA(HH, TextTPA, TPA, TPA) then
Inc(result);
end;
end;
end;