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 :)
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 :)