SRL Archive - SRL Bugs

GEBuyAt problem


putonajonny

2012-01-01 09:17:25

Date: 01/01/2012

Public/Development:
Revision #:

Debug Text: n/a

File Involved (if known): GrandExchange.scar

Screen Shots (if applicable): (not really)

In my script I use the line:
  GEFindFreeSpot(i);

Repeat
GEBuyAt(i);
Until(GEBuyMenu);
(The lines are actually much longer with failsafes in case it isn't actually in the GE etc. but that is the basis of it. The problem with the GEBuyAt function is that it has the lines:
  if IsUpText('Buy') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;
It is not recognising the UpText properly, The uptext says "Make Buy Offer" however if I insert a line in:
  WriteLn(GetUpText)

if IsUpText('Buy') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;
It outputs:
Make Bu^^ff^ ~ -. ..
coords: 41, 164
Make Bu^^ff^ ~ -. ..
coords: 41, 164
Make Bu^^ff^ ~ -. ..
coords: 41, 164
Make Bu^^ff^ ~ - ..
coords: 41, 164
Make Bu^^^^ t . .

Showing that it isn't able to read the uptext. I think the problem is currently the snowey background in the GE but a better way of recognising that it is at the right point would be better.

Here is my proposed solution:
When you mouse over one of the boxes you get this popping up in the exact same location every time:
If you run
WriteLn(GetTextAt( 52, 120, 0, 100, 10, 4305653, 5, 5, 'SmallCharsNS'))
It outputs:
Buy
So therefore if we can use this to detect if the mouse is in the right place.

My proposed solution:
We swap:
if IsUpText('Buy') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;
for:
if(GetTextAt( TB.x1 + 20, TB.y1 + 38, 0, 100, 10, 4305653, 5, 5, 'SmallCharsNS') = 'Buy') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;


The fill code for that function would then be:
function GEBuyAt(spot: integer): boolean;
var
TB: TBox;
x, y: integer;
begin
if not InGE then exit;
if not GEIsSpotFree(spot) then
begin
writeln('space is not free!');
exit;
end;

TB := GESpotToTBox(spot);
MouseBox(TB.x1 + 35, TB.y1 + 50, TB.x1 + 65, TB.y1 + 80, 3);
wait(150+Random(75));

WriteLn(GetUpText)

if(GetTextAt( TB.x1 + 20, TB.y1 + 38, 0, 100, 10, 4305653, 5, 5, 'SmallCharsNS') = 'Buy') then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, true);
end;

for x:= 0 to 9 do
begin
wait(100);
if GEBuyMenu then break;
end;

Result := GEBuyMenu;
end;


Test of my solution:
  for i := 1 to 2 do
begin
WriteLn('i = '+IntToStr(i));
TB := GESpotToTBox(i)
MouseBox(TB.x1 + 35, TB.y1 + 50, TB.x1 + 65, TB.y1 + 80, 3);
Wait(1000+Random(200))
WriteLn(GetTextAt( TB.x1 + 20, TB.y1 + 38, 0, 100, 10, 4305653, 5, 5, 'SmallCharsNS'))
If(GetTextAt( TB.x1 + 20, TB.y1 + 38, 0, 100, 10, 4305653, 5, 5, 'SmallCharsNS') = 'Buy') then
WriteLn('It Worked');
WriteLn(GESpotToTBox(i))
Wait(100+Random(50))
WriteLn('')
WriteLn('')
end;

Output:

i = 1
Buy
It Worked
(32, 82, 172, 194)


i = 2
Buy
(188, 82, 328, 194)


Successfully executed.

HT BaaFly

2012-01-01 09:25:05

I, too, have noticed this bug but finally decided to create my own. anyway, thx for reporting

eXoTiK

2012-01-01 10:20:20

It's a GetUpText error, not the GEBuyAt error. Even test the GetUpText on anything, it's all screwed up.

Narcle

2012-01-01 11:46:08

Need a OCR update for Uptext, its def really buggy right now. I'll mess around a bit and see if I can get it working.

putonajonny

2012-01-01 14:46:01

From: eXoTiK
It's a GetUpText error, not the GEBuyAt error. Even test the GetUpText on anything, it's all screwed up.


Even so, I think it would be more reliable doing it this way

Coh3n

2012-01-01 16:33:01

From: putonajonny
Even so, I think it would be more reliable doing it this way
OCR definitely needs to be fixed, but I agree with you. May not be a bad idea to make the text search box larger (like a box around the mouse position) in case the box is to ever pop up somewhere else.

Narcle

2012-01-01 18:30:37

From: Coh3n
OCR definitely needs to be fixed, but I agree with you. May not be a bad idea to make the text search box larger (like a box around the mouse position) in case the box is to ever pop up somewhere else.


Just use a FindColors() on whole screen and filter by SplitTPA(TPA, 1) get largest box and read it from there with GetTextWrapEx. The box color is constant atm. Can make one up when I get home.

putonajonny

2012-01-01 18:41:26

From: Coh3n
OCR definitely needs to be fixed, but I agree with you. May not be a bad idea to make the text search box larger (like a box around the mouse position) in case the box is to ever pop up somewhere else.


At the moment I put it to search atX and atY but changing that to a box wouldn't be that hard, can somebody test this for i := 3 to 6?

Narcle

2012-01-01 19:07:06

Function FindGEText(FindStr: String): Boolean;
var
ATPA: T2DPointArray;
TPA: TPointArray;
T: TPoint;
StrArr: Array of String;
i: Integer;
begin
GetClientDimensions(T.x, T.y);
FindColorsTolerance(TPA, 15133931, 0, 0, T.x-1, T.y-1, 0);
If Length(TPA) < 1 then
Exit;
ATPA := SplitTPA(TPA, 1);
SortATPASize(ATPA, True);
SetArrayLength(StrArr, Length(ATPA));
for i := 0 to High(ATPA) do
with GetTPABounds(ATPA[i]) do
begin
StrArr[i] := GetTextAtExWrap(x1, y1, x2, y2, 0, 3, 4, 4305653, 0, 'SmallCharsNS');
WriteLn(StrArr[i]);
end;
Result := StrInArr(FindStr, StrArr);
end;