Results 1 to 16 of 16

Thread: GetTextAtEx Help

  1. #1
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default GetTextAtEx Help

    I am trying to read the price under "Price Per Item:" and save it in a String.



    The code I am trying to use is:

    Code:
    procedure getText;
    var
       x,y : Integer;
    begin
         FindColor(x, y, 6400255,290,180,445,200);
         WriteLn(x);
         WriteLn(y);
         writeln((GetTextAtEx(x,y,50,UpChars,false,false,0,5,6400255,15,false,tr_AllChars)));
    end;
    The only output I am getting looks like this:

    Code:
    Successfully compiled (1698 ms)
    SRL Compiled in 16 msec
    320
    186
      ' '      í   
    Successfully executed
    The text appears to be UpChars after looking at the pictures in the Scar 3.21\Fonts\ directory and I know that the color is right. But I still can't seem to get the right output.

    Any suggestions would be greatly appreciated. Thanks.

    I cropped the picture so that the top left corner is supposed to be 0,0
    Last edited by scuz 10; 08-20-2009 at 01:09 PM.

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

    Default

    Scuz, you need to mess around with the parameters or try and -/+ onto your coordinates.
    However, saying this it is very well known that GetTextAtEx is a very sensitive function. You may benefit from this: http://www.villavu.com/forum/showthread.php?t=31983

    If after all that it fails then the Chars are wrong, this happened with PinScreen() as well.

    EDIT: sixfeetunder - wow! rep+
    Last edited by Naum; 08-20-2009 at 04:43 PM.

  3. #3
    Join Date
    Aug 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    The problem is that the coordinates you are getting are based on the color of the text. 320,186 is the first location of the color of the text, but not the location needed for GetTextAtEx to read the text. That location must be EXACT, and in this case is 319,186 because of the way the bitmaps for the text work.

    In short, you cannot simply use FindColor because it will not reliably return the correct location for the start of the text for GetTextAtEx. A better way to do it would be the following:

    Code:
    FindColorsTolerance(pts,col,s.x-20,s.y+57,s.x+30,s.y+66,10);
    bound:=GetTPABounds(pts);     
    text:=GetTextAtEx(bound.x1,s.y+59,50,chars,false,false,0,0,col,20,false,tr_AllChars);
    What this does is:
    1st Line: gets the locations (TPoints) of every pixel with the specified color and returns them in an array.
    2nd line: finds the bounds of the array. the point we want from this is the top left, in this case bound.x1 and bound.y1. If done correctly in your case, this would return the 319 for X that you need.
    3rd line: retrieve the text from the given coordinates.

    I hope this helps. My explanation may not be great but I am pretty tired now. Feel free to PM me or respond and I'll try to check this thread tomorrow if you need more help.

  4. #4
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    NaumanAkhlaQ: I tried that and still no success.

    sixfeetunder: How exactly would I implement that into my code. I am guessing that pts would be and integer array but what is 's' and what is 'bound'?

  5. #5
    Join Date
    Aug 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    pts is a TPointArray (TPA). bound is a TBox. s is specific to the method of mine i stole it from. where those are should just be X and Y values of the top left and bottom right corners of the box to populate the TPA from. Look at this tutorial for a better understanding:

    http://www.villavu.com/forum/showthr...ht=TPointArray

    TPA's can be extremely helpful once you learn how to use them properly.

  6. #6
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Then shouldn't the third line read?:

    Code:
    text:=GetTextAtEx(bound.x1,bound.y1,50,chars,false,false,0,0,col,20,false,tr_AllChars);
    i have changed the s.y+59 to bound.y1

  7. #7
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ok so I implemented what you said but I still don't get a better result. Maybe I am doing it wrong:

    Code:
    procedure getText;
    var
       text : String;
       pts : TPointArray;
       bound : TBox;
    begin
         FindColorsTolerance(pts,6400255,290,180,445,200,10);
         bound:=GetTPABounds(pts);
         text:=GetTextAtEx(bound.x1,bound.y1,50,UpChars,false,false,0,0,6400255,20,false,tr_AllChars);
         WriteLn(text);
    end;

  8. #8
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Update:

    Got it working!!! :ddddddddd :dddddddd

    thanks for the help

  9. #9
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Please don't do double posts. The edit button there is not a joke. You can edit your post with it.

    Anyway it's nice to see two registered user talking on this level.

    And isn't that box is static? Can't we use static parameters? Or GetTextAtEx won't work with too much nothing on the edges of the search area? My bet that it will work. But of course getting the bound of it is more precise. But personally I don't like overcomplicated functions that can be done easier.

  10. #10
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ok sorry about the double post...

    But now I have a much simpler question in mind.

    I am trying to write string to a file but I want to separate each string with a new line so it would look like this:

    String A
    String B
    String C
    But all I get is:

    String AString BString C
    I think I have to use a byte code but I dont know the byte code for 'ENTER'.

  11. #11
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    When I try to use it the only thing I got is squares in the file.
    So it would be something like this:
    String A(stupid suare here)String B(stupid suare here)String
    But you can press F1 in scar and at the top there are the codes.
    If anyone know how to separate lines with a simple character in scar I want to know that two. But "enter" doesn't work for me.

  12. #12
    Join Date
    Aug 2009
    Posts
    10
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Sabzi View Post
    And isn't that box is static? Can't we use static parameters? Or GetTextAtEx won't work with too much nothing on the edges of the search area? My bet that it will work. But of course getting the bound of it is more precise. But personally I don't like overcomplicated functions that can be done easier.
    Sabzi, yes that box is static, but the starting pixel location for the text is not because the text is centered within that box. When retrieving unknown text you must have the exact starting location which, as I said, is not static therefore we must use TPA's.

    scuz 10, glad to see you got it working!

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

    Default

    Quote Originally Posted by scuz 10 View Post
    Ok sorry about the double post...

    But now I have a much simpler question in mind.

    I am trying to write string to a file but I want to separate each string with a new line so it would look like this:



    But all I get is:



    I think I have to use a byte code but I dont know the byte code for 'ENTER'.
    When you want to write something to a file the way to separate lines are the keys: +#10+#13

  14. #14
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    [threadhijack]
    What I was talking about before: (I know the 13 and 10 anyway)

    Script:
    SCAR Code:
    program New;

    var
      I: Integer;

    begin
      I := RewriteFile(ScriptPath + 'testtxt.txt', True);
      WriteFileString(I, 'test' + #10 + #13 + 'test');
      CloseFile(I);
    end.

    Output: attachment because if I copy/paste it it's fine

    Haha I realized that this is something with notepad. So I decided to download caderno and it's fine. Lol and I thought it's something with scar. I have tried CHR(10)/CHR(13)/#10/#13, etc with no success. And it was the notepad XD
    :facepalm: (You know that Jean-Luc Picard picture)
    [/threadhijack]

    I solved this while posting but I don't want to waste this lots of written letter.

  15. #15
    Join Date
    Aug 2009
    Posts
    164
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Sabzi,

    You can solve this problem by using the following proedure:

    Code:
    procedure SaveToTxt;
    var
      I: Integer;
    
    begin
      I := ReWriteFile(AppPath + 'SCRIPTprogressReport.txt', False);
      WriteFileString(I, GetDebugText);
      CloseFile(I);
    end;
    Bascially, you clear the text from the debug box, use writeln to add whatever you want on separate lines, then use the code above to copy the debug text into a notepad file. It will copy all the formatting, including the new lines

  16. #16
    Join Date
    Feb 2009
    Location
    Hungary (GMT + 1)
    Posts
    1,774
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Lolwut?
    I don't got any problem any more. Did you read my post? Anyway thanks for trying to help but that's basic, I knew that.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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