PDA

View Full Version : Text Grabbing/Finding - By Naum



Naum
06-29-2008, 06:26 PM
How To Find/ Get Text From An Area


Contents.

0 - Introduction

I - FindText

II – FindTextTPA

III - GetTextAtEx and Trim

IV - End Notes



0 - INTRODUCTION


In SCAR and SRL there are alot of text finding related procedures. A common one is 'IsUpText('');'. But how do you use otherways of finding text, one of my problems is that sometimes IsUpText doesn't work that well for me. This means I resort to text finding.
In SRL the Main Text Finding procedure is 'FindText', In this Tutorial I will aim to convey how text finding can be used in an array of problems. Enjoy :)!


I - FindText

Ok so what is FindText well let me scare you:

{************************************************* ******************************
function FindText(var cx, cy: Integer; txt: String; font, xs, ys, xe, ye: Integer): Boolean;
By: Stupid3ooo
Description: Searches for text in specified box with specified font.
************************************************** *****************************}

OMG you think, those parameters look scary, well lets tackle this. CX AND CY are the variables of where the text is, this is used mainly in GetTextAtEx. The next bit Txt this is the text your looking for so say:

In looking for the Click to continue text in the chat box, so we fill in our variables x, y of course and type in part of the letters in that line we are looking for. I will choose 'ontinue'.

So what it looks like so far:

If FindText(x, y, 'ontinue'

Wow we really did that?? Yes we did. With great Care, Of Course.
So.. lets tackle the next part - font here are a list of fonts that SRL has :

NPCChars := Chat text that the NPC makes e.g like the chat the Banker says like 'would you like to access your account?'
TradeChars := Not used but its the text in the trade screen e.g 'Accept'
SmallChars := Normal Chat text
StatChars := Letters of the stats
UpChars := The letters of the uptext

So we need NPCChars in font because when you talk to an NPC e.g Banker you always have to, annoyingly, click the 'Click to continue' shite.
The next part xs, ys, xe, ye: Integer is just the box the text is in, just like using FindColor. So for the ChatBox in runescape where the C2C text is we have:

If FindText(x, y, 'ontinue', NPCCHARS, MCX1, MCY1, MCX2, MCY2) Then

Yay we did it :).
A simple script:


Begin
If FindText(x, y, 'ontinue', NPCCHARS, MCX1, MCY1, MCX2, MCY2) Then
Mouse(x, y, 1, 1, True);
end.

Now for the next chapter....





II - FindTextTPA

*Warning this text finder requires more advanced techniques*

Now this is the most used Text Finder in SRL it uses TPA for finding text lets have a look.


{************************************************* ******************************
Function FindTextTpa(Color,Tol,xs,ys,xe,ye : integer; Txt : string; Chars : Integer; Action : (ClickLeft,ClickRight,Move,Nothing)) : Boolean;
By: Raymond
Description: Just like FindTextTPAEx, but without the x and y pos returning.
************************************************** *****************************}

Looks a bit like FindText except doesn't find text with 'exactness' it uses Color and Tolerance. This is very useful in finding text using a specified color. Ok so the list of colors it uses to work with:

clBlack - Black
ClMaroon - Dark Red
ClGreen - Green
ClRed - Red
ClYellow - Yellow
ClBlue - Blue
ClTeal - Teal (turquoise)
ClNavy - Dark Blue
ClPurple - Purple
ClGray - Gray
ClWhite - White

These are the main ones it uses to work with. So lets say we are finding Click to continue - again! The color would be ClBlue. The tolerance can be anything it doesn't really matter unless its not above 120 - this is used as the margin of error. So we can incorporate what we have used in FindText To make our end result:

If FindTextTPA(ClBlue, 30, MCX1, MCY1, MCX2, MCY2, 'ontinue', NPCChars, Nothing) Then

See its easy now you can show off to all your friends what lovely things you've mastered!



III - GetTextAtEx 'n' Trim

*Warning your going to need a bit of experience to get the hang of this*

GetTextAtEx is the only SCAR and SRL way to get text from an area, that i know of.

Lets have a look at its parameters:

(c) Quote taken from scar manual.


GetTextAtEx(x, y: Integer; Tolerance: Integer; Chars: Integer; CheckShadow, CheckOutline: Boolean; MinSpacing, MaxSpacing: Integer; TextColor: Integer; TextLength: Integer; Strict: Boolean; Range: TCharRange) : String;

OMG you say look at all those params get Chuck Norris Now!!!!! No, not really..

See its simple and logical (not really im just trying to sugar coat it :p) Its as hard as getting 99 woodcutting, The legit way!
Now I use FindText With this to get the text with the Click to continue but you can use this without it.

Ok the first bits are just the place where you want to find the chars in so get the co-ords of it the middle part of the Line of text and put it in, by the way I'm finding the C2C text again :).
So what I have:

GetTextAtEx(567, 867{not actual co-ords}

Next the Tolerance and Chars I would have Tolerance at 0 - 120 again its the margin of error. So what i have

GetTextAtEx(567, 867{not actual co-ords}, 50, NPCChars

CheckShadow and CheckOutline should be false as this is only for RuneScape Classic ;). I would say MinSpacing - which is the minimum spacing in the text to be '0' and the MaxSpacing - which is MaximumSpacing to be around 10 - 80. Now TextColor you can either pick yourself or choose from the list here it is again:

clBlack - Black
ClMaroon - Dark Red
ClGreen - Green
ClRed - Red
ClYellow - Yellow
ClBlue - Blue
ClTeal - Teal (turquoise)
ClNavy - Dark Blue
ClPurple - Purple
ClGray - Gray
ClWhite - White

So I would take blue (you should know why already) and this is how my Line looks like:

GetTextAtEx(567, 867{not actual co-ords}, 50, NPCChars, False, False, ClBlue

So what’s next ahh yes here it is the TextLength is just basically how many letters are in your text I would say around 80 because it doesn't really matter as you can trim - (See Next Section) the spaces later. Strict means: do we make the text finder be strict so if one colour is blue and the other is red it will quit. I would set that as False as you want the text.

But please note that this function was for use in RSC. Now this is what my line looks like:

GetTextAtEx(567, 867{not actual co-ords}, 50, NPCChars, False, False, ClBlue, 80, False

Now we get to the Range part as your thinking why not add a NPCCHARS to it..alas..it isn't that easy. The TCharRange is a different type of Characters which follow:

(c) Taken from the SCAR Manual

tr_AllChars - read all characters;
tr_BigLetters - read capital Latin letters;
tr_SmallLetters - read lowercase Latin letters;
tr_Digits - read digits;
tr_BigSymbols - read symbols that are big in size, like "=", "%", "$", etc;
tr_SmallSymbols - read small symbols like ".", ",", "'", etc;
tr_SecondTableChars - read symbols with character code above 127;
tr_Letters = tr_BigLetters or tr_SmallLetters;
tr_AlphaNumericChars = tr_Letters or tr_Digits;
tr_Symbols = tr_BigSymbols or tr_SmallSymbols;
tr_NormalChars = tr_AlphaNumericChars or tr_Symbols;

Mine would be AllChars because I’m lazy and it will work anyway.

My Final Line:

GetTextAtEx(567, 867{not actual co-ords}, 50, NPCChars, False, False, ClBlue, 80, False, tr_AllChars);

And a script to test it:

Var Answer : String;

Begin
Answer := GetTextAtEx(567, 867{not actual co-ords}, 50, NPCChars, False, False, ClBlue, 80, False, tr_AllChars);
WriteLn(Answer);
end.

So there you go..

Just remember, there are other ways of doing things, as zeph quoted :):

It really depends on what text you're searching for. If its chat box text or interface text which doesn't have variable spacing between characters setting both Min and Max Spacing as 0 will be fine. For MS text which does have varying spaces a Max Spacing will be required.

Also the 'Tolerance' parameter in GetTextAtEx is the tolerance of the colour of the text. In a lot of cases text colour is constant thus a tolerance is not needed.

I also have a suggestion. The x and y parameters in GetTextAtEx require a precise point in order for the function to successfully return all the text. What I usually do to get this point is call IsTextInAreaEx and find the text first. This returns the coords of the point at which the text is found and the point that you need to input into GetTextAtEx - makes it a lot easier than just randomly puting in points. You might want to add that to the tutorial.


Now what does Trim Do?

Trim is really easy to understand because all it does is to get rid of the spaces at the beginning and the end of the Text So instead of using that script and making it write in the Debug Box 'Click to Continue ' We can use a Trim Like this:

Var Answer : String;

Begin
Answer := Trim(GetTextAtEx(567, 867{not actual co-ords}, 50, NPCChars, False, False, ClBlue,80, False, tr_AllChars));
WriteLn(Answer);
end.

or

Var Answer : String;

Begin
Answer := GetTextAtEx(567, 867{not actual co-ords}, 50, NPCChars, False, False, ClBlue, 80, False, tr_AllChars);
Trim(WriteLn(Answer));
end.

It doesn't really matter where you put it but you should have this : 'Click to continue';



IV - End Note

The reason why I made this tutorial was because I spent my time looking through the include of SRL and finding all this GetTextAtEx and FindText. Hope I Helped all of you learn how to Grab and Find text.

Thank-you for reading :)

Naum
06-29-2008, 07:38 PM
Is Anyone going to reply to this?

StrikerX
06-29-2008, 08:44 PM
So if i use

GetTextAtEx(x, y: Integer; Tolerance: Integer; Chars: Integer; CheckShadow, CheckOutline: Boolean; MinSpacing, MaxSpacing: Integer; TextColor: Integer; TextLength: Integer; Strict: Boolean; Range: TCharRange) : String;

On a site that has security codes then will it WriteLn into the debug box?

Naum
06-30-2008, 10:22 AM
Yeah but you need to make the bitmap mask for the characters ;)

Laur€ns
06-30-2008, 10:36 AM
Wasn't it like the Chars are already in SCAR?

Loaded all chars. (NPCChars, TradeChars, SmallChars, StatChars, UpChars)
Nice tut btw, I knew there was some IsUpText built-in:) But not how to use it. Great thanks and rep+ ;)
Edit: Ah wait, it was with security codes :) NVM!

ZephyrsFury
06-30-2008, 10:39 AM
You can use LoadCharsFromFont2:



function LoadCharsFromFont2(fontname: string; fontsize: Integer; fontbold, fontitalic, fontunderline, fontstrike: Boolean): Integer;
Load characters from Windows font in memory.
Example:
c := LoadCharsFromFont2('Courier New', 10, False, False, False, False);


EDIT: Nice Tut btw Naum,

Couple of this though{



I would say MinSpacing - which is the minimum spacing in the text to be '0' and the MaxSpacing - which is MaximumSpacing to be around 10 - 80


It really depends on what text you're searching for. If its chat box text or interface text which doesn't have variable spacing between characters setting both Min and Max Spacing as 0 will be fine. For MS text which does have varying spaces a Max Spacing will be required.

Also the 'Tolerance' parameter in GetTextAtEx is the tolerance of the colour of the text. In a lot of cases text colour is constant thus a tolerance is not needed.

I also have a suggestion. The x and y parameters in GetTextAtEx require a precise point in order for the function to successfully return all the text. What I usually do to get this point is call IsTextInAreaEx and find the text first. This returns the coords of the point at which the text is found and the point that you need to input into GetTextAtEx - makes it a lot easier than just randomly puting in points. You might want to add that to the tutorial.

Lee Lok Hin
06-30-2008, 10:49 AM
I never understood CheckShadow, CheckOutline. Thanks a lot!

StrikerX
06-30-2008, 12:19 PM
Yeah but you need to make the bitmap mask for the characters ;)

Meh there is always a catch.....

Naum
06-30-2008, 12:20 PM
Ok thanks for the replies, yeah I use FindText (as I said) to get the points then to check for the text. But yeah I'll fix up the tutorial a little bit. Once again Thanks for the Replies

TViYH
07-03-2008, 12:57 PM
Very nice tutorial! Taught me quite a bit!

EvilChicken!
07-03-2008, 02:52 PM
Naum, this is a great tutorial.
(Only thing wrong is that I would prefer normal font colors instead, but thats just a matter of personal taste.)
I like how you are writing tutorials and don't ask for reputation.
Hmm.
*thinks*

*time passes*


*light bulb appears over head*
Oh, you want the cup, don't you?


:p

Anyway, nice tutorial, (I'm beginning to hate the word "nice") covers a lot of areas. I hope you'll continue writing tutorial like these.

Any plans for what next tutorial of yours will be about?

(Excuse my grammar..)

Naum
07-03-2008, 03:24 PM
Naum, this is a great tutorial.
(Only thing wrong is that I would prefer normal font colors instead, but thats just a matter of personal taste.)
I like how you are writing tutorials and don't ask for reputation.
Hmm.
*thinks*

*time passes*


*light bulb appears over head*
Oh, you want the cup, don't you?


:p

Anyway, nice tutorial, (I'm beginning to hate the word "nice") covers a lot of areas. I hope you'll continue writing tutorial like these.

Any plans for what next tutorial of yours will be about?

(Excuse my grammar..)

Thanks soo much EC and Elkins(always remember you as that). My next tutorials already underway so it should be done soon.

Once again thanks for all the replies.

Nava2
08-01-2008, 05:16 AM
Great Tutorial, deserves a bump. I actually understand how to use the text grabbing functions now!

Thanks!

Nava2

Naum
08-15-2008, 11:00 AM
No Problem, Thanks.

AzulDrake
08-25-2008, 08:07 AM
Been looking for this for a long time now :) thanx for this. Helped me alot.

Freddy1990
08-25-2008, 08:40 AM
Hmm, nice tutorial

Naum
08-25-2008, 09:34 AM
Hmm, nice tutorial

Hey Thanks alot man, I mainly found out about it from the SRL Manual. I ran a few scripts to get the text using FindText. But one thing I want to ask why do the SRL Include has 'x -2, y-3' subtracting numbers on the x and the y variables?

e.g
function GetBlackText(ChatLine: Integer): string;
var
TP: TPoint;
begin
TP := TextCoords(ChatLine);
Result := Trim(GetTextAtEx(TP.x - 2 {here}, TP.y - 2 {here}, 0, SmallChars, False, False, 0,
1, 0, 80, False, tr_AllChars));
end;

Thanks for the reply.

Claymore
08-26-2008, 07:38 AM
Amazing! 5 Stars and a thank you very much.

And i have no idea why SRL put those subtractions there.

Naum
08-27-2008, 11:43 AM
Thank - you very much :)

BazzBarrett
09-18-2008, 09:39 PM
very helpful tut thx =)

Wanted
07-28-2009, 08:53 AM
Nice tutorial, very much needed thanks.

Naum
07-28-2009, 05:56 PM
Nice tutorial, very much needed thanks.

Haha thanks man :)

Wanted
07-29-2009, 01:16 AM
You should really include what zephy said about doing FindTextEx then GetTextAtEx, to your tutorial.... it works really well.

Naum
07-29-2009, 02:35 AM
You should really include what zephy said about doing FindTextEx then GetTextAtEx, to your tutorial.... it works really well.

Sure, I'll add that right now. Cant believe I didn't see that comment :duh:
I guess I must have been too fast, now I can work on it. Thanks Zeph ++

Alligaattor
08-30-2009, 10:34 PM
I just cant figure out how to find text that pops up after right click on npc...
Either im stupid or just can't translate english to finnish :S

Sabzi
08-30-2009, 11:01 PM
I just cant figure out how to find text that pops up after right click on npc...
Either im stupid or just can't translate english to finnish :S

Use ChooseOption functions.
http://freddy1990.com/srlmanual/SRL/core/Text.html
http://freddy1990.com/srlmanual/SRL/core/Timing.html

The simple ChooseOption or WaitOption is enough most of the cases.

Hairy Pomegranate
09-03-2009, 10:56 AM
NPCChars := Chat text that the NPC makes e.g like the chat the Banker says like 'would you like to access your account?'
TradeChars := Not used but its the text in the trade screen e.g 'Accept'
SmallChars := Normal Chat text
StatChars := Letters of the stats
UpChars := The letters of the uptext
can you post screenshots of the examples of each text type? Specifically, I was wondering what the options text is, such as "Walk here" or "Climb-up Ladder" or "Wield Rune pickaxe," that appears at the top left of your screen.

ian.
09-03-2009, 11:40 AM
can you post screenshots of the examples of each text type? Specifically, I was wondering what the options text is, such as "Walk here" or "Climb-up Ladder" or "Wield Rune pickaxe," that appears at the top left of your screen.

Err.. "UpChars := The letters of the uptext"

Hairy Pomegranate
09-04-2009, 05:38 AM
Err.. "UpChars := The letters of the uptext"
oh that's called "uptext?" Thanks for the help :D

Mikkoz99
04-07-2013, 08:44 AM
Ok so I'm trying the FindText because I am trying to make antirandom for the pickaxe head falling off.
So I made this procedure (note it's just a test):

Procedure AxeHead;
begin
If FindText (x, y, 'ou need a pickaxe', NPCCHARS, MCX1, MCY1, MCX2, MCY2) Then
Mouse(x, y, 1, 1, True);
end;

But it returned this error:


[Error] C:\Users\Mikkoz\Desktop\IronMiner.simba(28:16): Unknown identifier 'x' at line 27
Compiling failed.

The x was this one: FindText (x <--
But then I tried adding Var

Procedure AxeHead;
Var
x, y: integer;
begin
If FindText (x, y, 'ou need a pickaxe', NPCCHARS, MCX1, MCY1, MCX2, MCY2) Then
Mouse(x, y, 1, 1, True);
end;

And it returns this:


Compiled successfully in 374 ms.

So my question is, is it detecting the text if it appears?

Sjoe
04-07-2013, 08:49 AM
Ok so I'm trying the FindText because I am trying to make antirandom for the pickaxe head falling off.
So I made this procedure (note it's just a test):

Procedure AxeHead;
begin
If FindText (x, y, 'ou need a pickaxe', NPCCHARS, MCX1, MCY1, MCX2, MCY2) Then
Mouse(x, y, 1, 1, True);
end;

But it returned this error:

The x was this one: FindText (x <--
But then I tried adding Var

Procedure AxeHead;
Var
x, y: integer;
begin
If FindText (x, y, 'ou need a pickaxe', NPCCHARS, MCX1, MCY1, MCX2, MCY2) Then
Mouse(x, y, 1, 1, True);
end;

And it returns this:

So my question is, is it detecting the text if it appears?

Make a new thread instead of posting it on a 4 year old one lol

Also use BlackChatMessage or something.