Page 1 of 2 12 LastLast
Results 1 to 25 of 31

Thread: Text Grabbing/Finding - By Naum

  1. #1
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default Text Grabbing/Finding - By Naum

    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:
    PHP Code:
     {*******************************************************************************
    function 
    FindText(var cxcyIntegertxtStringfontxsysxeyeInteger): Boolean;
    ByStupid3ooo
    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:

    SCAR Code:
    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:

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

    Yay we did it .
    A simple script:

    SCAR Code:
    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.

    PHP Code:
    {*******************************************************************************
    Function 
    FindTextTpa(Color,Tol,xs,ys,xe,ye integerTxt stringChars IntegerAction  : (ClickLeft,ClickRight,Move,Nothing)) : Boolean;
    ByRaymond
    Description
    Just like FindTextTPAExbut 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:

    SCAR Code:
    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.

    PHP Code:
    GetTextAtEx(xyIntegerToleranceIntegerCharsIntegerCheckShadowCheckOutlineBooleanMinSpacingMaxSpacingIntegerTextColorIntegerTextLengthIntegerStrictBooleanRangeTCharRange) : 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 ) 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:

    SCAR Code:
    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

    SCAR Code:
    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:

    SCAR Code:
    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:

    SCAR Code:
    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:

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

    And a script to test it:

    SCAR Code:
    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:

    SCAR Code:
    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

    SCAR Code:
    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
    Last edited by Naum; 12-08-2012 at 09:24 PM.

  2. #2
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Is Anyone going to reply to this?

  3. #3
    Join Date
    Jun 2007
    Location
    Liverpool ,Nsw,Australia
    Posts
    740
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    So if i use
    SCAR Code:
    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?
    Quote Originally Posted by Darkmage View Post
    I got 2 questions'
    #1. When i run the script will it automatically pick up the mouse and move?

  4. #4
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Yeah but you need to make the bitmap mask for the characters

  5. #5
    Join Date
    Mar 2008
    Location
    The Netherlands
    Posts
    1,395
    Mentioned
    1 Post(s)
    Quoted
    1 Post(s)

    Default

    Wasn't it like the Chars are already in SCAR?

    SCAR Code:
    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!


  6. #6
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    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.

  7. #7
    Join Date
    Apr 2007
    Posts
    994
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    I never understood CheckShadow, CheckOutline. Thanks a lot!
    [QUOTE]<GoF`> oh no its Raymooond
    <Raymooond> Heya
    <GoF`> is it ray or some other ray?
    <LeeLokHin> No idea
    <LeeLokHin> Raymond, what's the game you like the most?
    <Raymooond> Runescape
    <-- LeeLokHin has kicked Raymooond from #srl (Faker.)[/QUOTE]

  8. #8
    Join Date
    Jun 2007
    Location
    Liverpool ,Nsw,Australia
    Posts
    740
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    Yeah but you need to make the bitmap mask for the characters
    Meh there is always a catch.....
    Quote Originally Posted by Darkmage View Post
    I got 2 questions'
    #1. When i run the script will it automatically pick up the mouse and move?

  9. #9
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    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

  10. #10
    Join Date
    Apr 2007
    Posts
    2,593
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Very nice tutorial! Taught me quite a bit!

  11. #11
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    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?




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

  12. #12
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by EvilChicken! View Post
    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?




    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.

  13. #13
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    Great Tutorial, deserves a bump. I actually understand how to use the text grabbing functions now!

    Thanks!

    Nava2
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  14. #14
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    No Problem, Thanks.

  15. #15
    Join Date
    Aug 2008
    Location
    Serdia, Isla Prima
    Posts
    68
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Been looking for this for a long time now thanx for this. Helped me alot.

  16. #16
    Join Date
    Feb 2006
    Location
    Belgium
    Posts
    3,137
    Mentioned
    3 Post(s)
    Quoted
    5 Post(s)

    Default

    Hmm, nice tutorial

  17. #17
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by Freddy1990 View Post
    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
    SCAR Code:
    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.

  18. #18
    Join Date
    Dec 2006
    Posts
    908
    Mentioned
    1 Post(s)
    Quoted
    17 Post(s)

    Default

    Amazing! 5 Stars and a thank you very much.

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

  19. #19
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Thank - you very much

  20. #20
    Join Date
    May 2008
    Location
    Here :p
    Posts
    194
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    very helpful tut thx =)

  21. #21
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Thumbs up

    Nice tutorial, very much needed thanks.

  22. #22
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by IceFire908 View Post
    Nice tutorial, very much needed thanks.
    Haha thanks man

  23. #23
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You should really include what zephy said about doing FindTextEx then GetTextAtEx, to your tutorial.... it works really well.

  24. #24
    Join Date
    Mar 2007
    Posts
    4,810
    Mentioned
    3 Post(s)
    Quoted
    3 Post(s)

    Default

    Quote Originally Posted by IceFire908 View Post
    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
    I guess I must have been too fast, now I can work on it. Thanks Zeph ++

  25. #25
    Join Date
    Mar 2007
    Location
    Finland, Espoo
    Posts
    96
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    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

Page 1 of 2 12 LastLast

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Grabbing or reading Text from a game text box
    By British in forum OSR Help
    Replies: 16
    Last Post: 02-27-2009, 08:02 AM
  2. Help with finding text
    By AzulDrake in forum OSR Help
    Replies: 2
    Last Post: 09-26-2008, 02:31 PM
  3. Need Help With finding text!
    By Macrosoft in forum OSR Help
    Replies: 16
    Last Post: 08-13-2007, 08:42 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •