SRL Archive - SRL Bugs

GetChooseOptions TextType parameter unused


riwu

2012-10-02 07:12:51

I was looking into how the TextType parameter (used in Option functions) treat 'action' and 'player', two rather distinct color as the same. And to my surprise, TextType isn't used in the function at all, meaning that no matter what you input as parameter will have no impact at all (you can even put a random string of numbers and not get any error).

Code below for quick reference.
GetChooseOptions
~~~~~~~~~~~~~~~~

.. code-block:: pascal

function GetChooseOptions(TextType: string): Array of TOptions;

Gets the texe from the options menu.

.. note::

by Wizzup? & Narcle

Example:

.. code-block:: pascal

*)
Function GetChooseOptions(TextType: string): Array of TOptions;
var
B, BB, sB, BigBox: TBox;
TPA, TPA1, TPA2: TPointArray;
ATPA, tempatpa: T2DPointArray;
I, L, target, bmp,w,h, cts: Integer;
BoxColors: TIntegerArray;
begin
target := GetImageTarget;
GetClientDimensions(B.X2, B.Y2);
B := IntToBox(0, 0, B.X2-1, B.Y2-1);
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(1);
// Black, Top Blue, grey
BoxColors := [131843, 3682593, 3552822];
SetLength(ATPA, Length(BoxColors));
for i := 0 to High(BoxColors) do
FindColorsTolerance(ATPA[i], BoxColors[i], B.X1, B.Y1, B.X2, B.Y2, 0);
TPA := MergeATPA(ATPA);
If Length(TPA) < 100 Then
begin
ColorToleranceSpeed(cts);
Exit;
end;

ATPA := SplitTPA(TPA, 4);
For i := 0 to High(ATPA) do
begin
B := GetTPABounds(ATPA[i]);
if ((B.x2-B.x1) > 90) and ((B.y2-B.y1) > 18) then
Break
else
B := IntToBox(0, 0, 0, 0);
end;

If (B.x2 = 0) then
begin
ColorToleranceSpeed(cts);
Exit;
end;

BigBox := B;

SetColorToleranceSpeed(3);
FindColorsTolerance(TPA1, 4996381, B.X1, B.Y1, B.X2, B.Y2, 18);//One color covers both Highlighted and non
sB := GetTPABounds(TPA1);
ReturnPointsNotInTPAWrap(TPA1, sB, TPA);
FindColorsTolerance(TPA2, 460291, B.X1, B.Y1, B.X2, B.Y2, 6);//shadow
SetColorToleranceSpeed(cts);

bmp := CreateBitmap(B.X2-B.X1+2, B.Y2-B.Y1+2);
OffsetTPA(TPA, Point(-B.X1, -B.Y1));
OffsetTPA(TPA2, Point(-B.X1, -B.Y1));
FastDrawClear(bmp, 0);
DrawTPABitmap(bmp, TPA, clRed);//Text
DrawTPABitmap(bmp, TPA2, clPurple);//Shadow
ocr_FilterUpTextByCharacteristics(GetMufasaBitmap(bmp));
GetbitmapSize(bmp,w,h);
SetTargetBitmap(bmp); // new target for findcolorstolerance.
SetLength(ATPA, H div 16);
for i := 0 to High(ATPA) do
FindColorsTolerance(ATPA[i], clRed, 0, 2+i*16, W-1, 18+i*16, 0);//+2 to y to line it up
L := High(ATPA);
SortATPAFromFirstPointY(ATPA, Point(w div 2,0));

SetArrayLength(Result, Length(ATPA));
Result[0].BigBox := BigBox;
for i := 0 to high(ATPA) do
begin
TPA := ATPA[i];
tempatpa := SplitTPAEx(TPA, 1, 10); // Split one into characters
SortATPAFromFirstPointX(tempatpa, Point(0, 0));
Result[i].Str := GetTextATPA(tempatpa, 5, 'UpCharsEx'); //Writeln(Result[i].Str);
BB := GetTPABounds(ATPA[i]);
Result[i].Bounds := IntToBox(BB.X1+B.X1, BB.Y1+B.Y1, BB.X2+B.X1, BB.Y2+B.Y1);
setlength(tempatpa,0);
setlength(TPA,0);
end;
ColorToleranceSpeed(cts);
SetImageTarget(target);
FreeBitmap(bmp);
end;

From comments of related functions:
Searches for TextType you input.
'action', 'player': The white text
'item': The orange text
'npc': The yellow text
'object': The cyan text
'all': Searches for all colors of text.
Will default to 'all'.

Coh3n

2012-10-02 08:03:17

Yeah, this has been like that for a while I think. It's not really a bug, though. The parameter was used in the past, but if we were to remove it now, it would break a lot of scripts, which would be a pain.

It will be removed for the next version of SRL, though.

riwu

2012-10-02 08:27:16

From: Coh3n
Yeah, this has been like that for a while I think. It's not really a bug, though. The parameter was used in the past, but if we were to remove it now, it would break a lot of scripts, which would be a pain.

It will be removed for the next version of SRL, though.

Why was it removed? It could be useful in some situations for more accurate option choosing.

Coh3n

2012-10-02 08:48:42

I'm not 100% sure because I'm not the only who rewrote the algorithm (I think Narcle did it), but the function used to look for the text color (hence, the parameter) and get a text from that. Some time ago, the choose option menu was updated, and that method proved to be unreliable.

Now, I think, it finds the menu's background color, then gets text from the points that aren't that color. So basically, it will find all the text in the menu no matter what, rather that a specific type (or color).

I hope that was clear. :)

Narcle

2012-10-02 14:03:05

From: Coh3n
I'm not 100% sure because I'm not the only who rewrote the algorithm (I think Narcle did it), but the function used to look for the text color (hence, the parameter) and get a text from that. Some time ago, the choose option menu was updated, and that method proved to be unreliable.

Now, I think, it finds the menu's background color, then gets text from the points that aren't that color. So basically, it will find all the text in the menu no matter what, rather that a specific type (or color).

I hope that was clear. :)


Correct. They really tried to break our scripts with tons of changes to ChooseOption. It had to be reworked constantly to keep up with it, so finally with Wizzups help I came up with the current one. Hasn't broken yet? (just color change now and then I've seen in SRL git)

The colors change too much for TextType to be used anymore.

riwu

2012-10-05 10:34:46

Thanks for the clarification! While i agree that it may be better to keep the parameter temporary to avoid breaking too many scripts, the comments in the include should at least be edited to communicate the changes.

Most people may still think TextType works and rely on it to differentiate between different options. I understand that the dev may be too busy with actual coding to be bothered with writing stories…hopefully the situation will improve with more SSRL joining the team ;)