SRL Archive - OSR Help

Get text from screen


Kyle Undefined

2011-11-12 11:11:14

Ok, so I've been trying to get this to work for awhile now. Here is the screen that I'm trying to get the text off of.


I have the detection for this screen done and working. I've tried getting the text for the "Hit ___" text, but no matter what chars I use, I can't seem to get the text. The same goes with the "Score" total to the right. I have the right colors and I'm setting the box around the correct areas. I just don't know what to do or try now.

I'm using this script to test, I change the values around after each run and try again, but I haven't gotten lucky so far :(

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

var
charArr : TStringArray;
I, x, y : Integer;

begin
setupsrl;
charArr := [BigChars, CharsNPC, CharsTrade, FriendChars, LoginChars, SmallChars, StatChars, UpChars, XPChars];
for I := 0 to High(charArr) do
begin
if GetTextAt(410, 190, 0, 3, 4, 10092288, 0, 20, charArr[I]) <> '' then
WriteLn('Found text with char ' + charArr[I] + ', text is ' + GetTextAt(410, 190, 0, 3, 4, 10092288, 0, 20, charArr[I]));
end;
end.

I've also tried this approach, but it errors out…

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

var
charArr, txtArr : TStringArray;
I, II, x, y : Integer;

begin
setupsrl;
charArr := [BigChars, CharsNPC, CharsTrade, FriendChars, LoginChars, SmallChars, StatChars, UpChars, XPChars];
txtArr := ['Black', 'Blue', 'Red', 'Yellow', 'Bulls-Eye'];
for I := 0 to High(charArr) do
begin
for II := 0 to High(txtArr) do
begin
if FindText(x, y, txtArr[II], charArr[I], MSX1, MSY1, MSX2, MSY2) then
begin
WriteLn('Found text with char ' + charArr[I] + ', text found is ' + txtArr[II]);
Break;
end;
end;
end;
end.

This is the error I get: "Error: Exception: Access violation at line 125"

function CreateBitmapMaskFromText(txt,chars : string) : integer;
begin
result := BitmapFromText(txt,chars); <-------------- Line 125 in simba.simba
end;

Any ideas?

Bixby Sayz

2011-11-12 11:21:14

I would love to hear how you solve this. I have a similar problem trying to read the Amount text in the smelting interface. Looks like similar color/fonts.

Kyle Undefined

2011-11-12 11:28:57

Yeah, I don't know what else to do. Yours is a little easier to solve than mine :P

NCDS

2011-11-12 11:43:08

Try this

{*******************************************************************************
function FindTextTpaEx(Color,Tol,xs,ys,xe,ye : integer;var x,y : integer; Txt : string; Chars : Integer; Action : (ClickLeft,ClickRight,Move,Nothing)) : Boolean;
By: Raymond
Description: Uses TPA's to find text..Returns the found pos in x and y (if not found both are 0)
In action you can put what you want to do after its found..
Nothing - Just return wether its found
Move - Just move the mouse to it
Clickleft - Movemouse & Clickmouse left
Clickright - MoveMouse & Clickmouse right
*******************************************************************************}

weequ

2011-11-12 11:48:02

Your second approach looks better in my opinion. It's also possible that srl doesn't have that charset and you would have to make it yourself.

What error are you getting with the second one?

Kyle Undefined

2011-11-12 12:50:27

From: NCDS
Try this

{*******************************************************************************
function FindTextTpaEx(Color,Tol,xs,ys,xe,ye : integer;var x,y : integer; Txt : string; Chars : Integer; Action : (ClickLeft,ClickRight,Move,Nothing)) : Boolean;
By: Raymond
Description: Uses TPA's to find text..Returns the found pos in x and y (if not found both are 0)
In action you can put what you want to do after its found..
Nothing - Just return wether its found
Move - Just move the mouse to it
Clickleft - Movemouse & Clickmouse left
Clickright - MoveMouse & Clickmouse right
*******************************************************************************}


NCDS, is that for finding text you already know you're looking for? So using that function, I'd use it with my second approach correct?


From: weequ
Your second approach looks better in my opinion. It's also possible that srl doesn't have that charset and you would have to make it yourself.

What error are you getting with the second one?


This is the error I get: "Error: Exception: Access violation at line 125" It pulls up Simba.simba and goes here:
function CreateBitmapMaskFromText(txt,chars : string) : integer;
begin
result := BitmapFromText(txt,chars);
end;
Line 125 is the result being set.

I'll try NCDS's function and see how it works.This is really aggravating though!


Edit:
So I got it working, I threw a try…catch around the FindTextTPAEx and it allowed it to continue even with the error. Now I know what chars to use for the search and it seems to work really well. Here is the final test script that I used.


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

var
charArr, txtArr : TStringArray;
I, II, x, y : Integer;

begin
setupsrl;
ClearDebug();
charArr := [BigChars, CharsNPC, CharsTrade, FriendChars, LoginChars, SmallChars, StatChars, UpChars, XPChars];
txtArr := ['Black', 'Blue', 'Red', 'Yellow', 'Bulls-Eye', 'Missed'];
for I := 0 to High(charArr) do
begin
WriteLn('Looking at text with char ' + charArr[I]);
for II := 0 to High(txtArr) do
begin
WriteLn('Looking for the text ' + txtArr[II]);
try
if FindTextTpaEx(65535, 0, MSX1, MSY1, MSX2, MSY2, x, y, txtArr[II], charArr[I], Nothing) then
begin
WriteLn('Found text with char ' + charArr[I] + ', text found is ' + txtArr[II]);
Break;
end;
except
WriteLn('Error! ' + exceptionToString(exceptionType, exceptionParam));
end;
end;
end;
end.

Oh, here's the output that it gave:


Looking at text with char BigChars
Looking for the text Black
Looking for the text Blue
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Looking for the text Missed
Looking at text with char CharsNPC
Looking for the text Black
Looking for the text Blue
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Looking for the text Missed
Looking at text with char CharsTrade
Looking for the text Black
Error! Exception: Access violation
Looking for the text Blue
Error! Exception: Access violation
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Error! Exception: Access violation
Looking for the text Missed
Looking at text with char FriendChars
Looking for the text Black
Looking for the text Blue
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Looking for the text Missed
Looking at text with char LoginChars
Looking for the text Black
Looking for the text Blue
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Looking for the text Missed
Looking at text with char SmallChars
Looking for the text Black
Looking for the text Blue
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Looking for the text Missed
Looking at text with char StatChars
Looking for the text Black
Looking for the text Blue
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Looking for the text Missed
Looking at text with char UpChars
Looking for the text Black
Looking for the text Blue
Looking for the text Red
Looking for the text Yellow
Looking for the text Bulls-Eye
Looking for the text Missed
Found text with char UpChars, text found is Missed
Looking at text with char XPChars
Looking for the text Black
Error! Exception: Access violation
Looking for the text Blue
Error! Exception: Access violation
Looking for the text Red
Error! Exception: Access violation
Looking for the text Yellow
Error! Exception: Access violation
Looking for the text Bulls-Eye
Error! Exception: Access violation
Looking for the text Missed
Error! Exception: Access violation
Successfully executed.

Thank you NCDS and weequ for your help! :) Hopefully this can help others as well.

mastaraymond

2011-11-12 16:48:48

From: Camo Developer
Ok, so I've been trying to get this to work for awhile now. Here is the screen that I'm trying to get the text off of.


I have the detection for this screen done and working. I've tried getting the text for the "Hit ___" text, but no matter what chars I use, I can't seem to get the text. The same goes with the "Score" total to the right. I have the right colors and I'm setting the box around the correct areas. I just don't know what to do or try now.

I'm using this script to test, I change the values around after each run and try again, but I haven't gotten lucky so far :(

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

var
charArr : TStringArray;
I, x, y : Integer;

begin
setupsrl;
charArr := [BigChars, CharsNPC, CharsTrade, FriendChars, LoginChars, SmallChars, StatChars, UpChars, XPChars];
for I := 0 to High(charArr) do
begin
if GetTextAt(410, 190, 0, 3, 4, 10092288, 0, 20, charArr[I]) <> '' then
WriteLn('Found text with char ' + charArr[I] + ', text is ' + GetTextAt(410, 190, 0, 3, 4, 10092288, 0, 20, charArr[I]));
end;
end.

I've also tried this approach, but it errors out…

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

var
charArr, txtArr : TStringArray;
I, II, x, y : Integer;

begin
setupsrl;
charArr := [BigChars, CharsNPC, CharsTrade, FriendChars, LoginChars, SmallChars, StatChars, UpChars, XPChars];
txtArr := ['Black', 'Blue', 'Red', 'Yellow', 'Bulls-Eye'];
for I := 0 to High(charArr) do
begin
for II := 0 to High(txtArr) do
begin
if FindText(x, y, txtArr[II], charArr[I], MSX1, MSY1, MSX2, MSY2) then
begin
WriteLn('Found text with char ' + charArr[I] + ', text found is ' + txtArr[II]);
Break;
end;
end;
end;
end.

This is the error I get: "Error: Exception: Access violation at line 125"

function CreateBitmapMaskFromText(txt,chars : string) : integer;
begin
result := BitmapFromText(txt,chars); <-------------- Line 125 in simba.simba
end;

Any ideas?

Fixed your "bug" in Simba.

(You were using sets of fonts that didn't include all of the characters you searched for)

Kyle Undefined

2011-11-12 16:52:19

From: mastaraymond
Fixed your "bug" in Simba.

(You were using sets of fonts that didn't include all of the characters you searched for)


Yeah, I realized that after I got it working lol -.-

mormonman

2011-11-12 17:12:06

You could have done this easier with a CountColor….