Results 1 to 12 of 12

Thread: Need function: OptionCount(Texts: TStringArray): integer

  1. #1
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default Need function: OptionCount(Texts: TStringArray): integer

    I dont know alot about text finding, so i thought someone could maybe write me this function? I already checked that 1 row is about 15.4 pixels high ^^

    It'd work like this:
    There are 3 items in the ground. I right click there, and call function
    Writeln('There are '+IntToStr(OptionCount(['Take']))+' items in the ground!');
    this should print text
    "There are 3 items in the ground!"

  2. #2
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    i shall make it (as long as no one else does first...)

    ~shut

    EDIT: sorry i had to go out
    but try this
    SCAR Code:
    function OptionCount(Text: string): Integer;
    var
      TP: TPoint;
      xx: Integer;
    begin
      while IsTextInAreaEx(xx, 0, 764, 502, TP.x, TP.y, Text, 3, UpChars, false, false, 0, 0, 4231423) do
      begin
        Inc(Result);
        xx:= TP.x+15;
      end;
    end;
    i havent managed to test it as i am running linux but it should work
    Last edited by Shuttleu; 08-07-2009 at 03:58 AM.

  3. #3
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I recall that he wanted a TStringArray but, i suppose you could make a seperate array, using i etc.
    If this works, I don't see why it wouldn't be in SRL .

  4. #4
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by Smarter Child View Post
    I recall that he wanted a TStringArray but, i suppose you could make a seperate array, using i etc.
    If this works, I don't see why it wouldn't be in SRL .
    'tis easy to do...

    SCAR Code:
    function OptionCount(Texts: TStringArray): Integer;
    var
      TP: TPoint;
      xx, i: Integer;
    begin
      for i := 0 to High(Texts) do
        while IsTextInAreaEx(xx, 0, 764, 502, TP.x, TP.y, Texts[i], 3, UpChars, false, false, 0, 0, 4231423) do
        begin
          Inc(Result);
          xx:= TP.x+15;
        end;
    end;

    I don't think that is exactly what marpis is looking for...

    Edit: Looked into it...
    SCAR Code:
    function CountOptions(Texts: TStringArray): Integer;
    var
       B: TBox;
       TPA, TextTPA: TPointArray;
       aTPA: T2DPointArray;
       I, C, H, HH, ii, L: Integer;
       P: TPoint;
       Occurances: array [0..2] of TPointArray;
    begin
      GetClientDimensions(B.X2, B.Y2);
      B.X1 := 0;
      B.Y1 := 0;
      SetLength(aTPA, 2);
      FindColorsTolerance(aTPA[0], 4409686, B.X1, B.Y1, B.X2, B.Y2, 0);
      FindColorsTolerance(aTPA[1], 4016722, B.X1, B.Y1, B.X2, B.Y2, 0);
      TPA := MergeATPA(aTPA);
      SetLength(aTPA, 0);
      If Length(TPA) < 10 Then
        Exit;
      B.X2 := 0;
      B.Y2 := 0;

      P := TPA[0];
      H := High(TPA);
      Dec(H);
      For I := 0 To H Do
        If TPA[i].X = TPA[I+1].X - 1 Then
        Begin
          If C > 5 Then
          Begin
            B.X1 := P.X;
            B.Y1 := P.Y;
            Break;
          End Else
            C := C + 1;
        End
        Else
        Begin
          P := TPA[I + 1];
          C := 0;
        End;
      If I = Length(TPA) Then
      Begin
        WriteLn('Choose Option Menu Getting Failed');
        Exit;
      End;
      InvertTPA(TPA);
      C := 0;
      P := TPA[0];
      H := High(TPA);
      Dec(H);
      For I := 0 To H Do
        If TPA[i].X = TPA[I+1].X + 1 Then
        Begin
          If C > 5 Then
          Begin
            B.X2 := P.X;
            B.Y2 := P.Y;
            Break;
          End Else
            C := C + 1;
        End Else
        Begin
          P := TPA[I + 1];
          C := 0;
        End;
      If I = Length(TPA) Then
      Begin
        WriteLn('Choose Option Menu Getting Failed');
        Exit;
      End;

      TPA := [];
      begin
        FindColorsTolerance(Occurances[0], 1845035, B.X1, B.Y1, B.X2, B.Y2, 0);
        FindColorsTolerance(Occurances[1], clBlack, B.X1, B.Y1, B.X2, B.Y2, 0);
        FindColorsTolerance(Occurances[2], 6121839, B.X1, B.Y1, B.X2, B.Y2, 0);
        TPA := MergeATPA(Occurances);

        ClearDoubleTPA(TPA);
        TPA := ReturnPointsNotInTPA(TPA, B);
      end;
      if High(TPA) < 1 then TPA := MergeATPA(Occurances);
      aTPA := SplitTPAEx(TPA, 7, 1);
      SortATPAFromFirstPoint(aTPA, Point(B.x1, B.y1));

      H := High(Texts);
      L := High(aTPA);

      For I :=0 To H do
      begin
        TextTPA := LoadTextTPA(Texts[i], UpChars, HH);
        for ii := 0 to L do
          If FindTextTPAInTPA(HH, TextTPA, aTPA[ii], TPA) Then
          Begin
            Inc(Result);
          End;
      end;

      if (Result > 0) then Exit;
      MMouse(B.X1 - 50, B.Y1 - 50, 40, B.Y2 - B.Y1);
      Wait(200 + Random(100));
    end;

  5. #5
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    SCAR Code:
    For I :=0 To H do
      begin
        TextTPA := LoadTextTPA(Texts[i], UpChars, HH);
        for ii := 0 to L do
          If FindTextTPAInTPA(HH, TextTPA, aTPA[ii], TPA) Then
          Begin
            Inc(Result);
            Exit;
          End;
      end;

    I dont think you really want to Exit there?

  6. #6
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Oops, lol my bad.
    Test the fixed one now.

  7. #7
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    mormonman, thats not what i meant ^^
    I meant that if there are 4 items in the ground, then there is 4 times text "Take" in the optionbox. So CountOptions(['Take']) returns 4 in this case.

    edit: i think i try this on my own too
    Last edited by marpis; 08-08-2009 at 10:15 PM.

  8. #8
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    Choose Option
    -- Examine CowHide
    -- Take Cowhide
    -- Examine Beef
    -- Take Beef
    -- Examine Bones
    -- Take bones


    basically what you are looking for is a function that will count the bolded parts, right?

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  9. #9
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by marpis View Post
    mormonman, thats not what i meant ^^
    I meant that if there are 4 items in the ground, then there is 4 times text "Take" in the optionbox. So CountOptions(['Take']) returns 4 in this case.

    edit: i think i try this on my own too
    mine does exactly that, maybe you should at least test it...

  10. #10
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    mine does exactly that, maybe you should at least test it...
    It returns 0 all the time, plus it moves the mouse which is not good

  11. #11
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

    Default

    did you try mine?

    ~shut

    EDIT: just tested it and found a mistake i made
    here is a perfetly workin one
    SCAR Code:
    function OptionCount(Text: string): Integer;
    var
      TP: TPoint;
      yy: Integer;
    begin
      while IsTextInAreaEx(0, yy, 764, 502, TP.x, TP.y, Text, 3, UpChars, false, false, 0, 0, 9812166) do
      begin
        Inc(Result);
        yy:= TP.y+15;
      end;
    end;
    Last edited by Shuttleu; 08-12-2009 at 01:53 AM.

  12. #12
    Join Date
    Aug 2008
    Location
    Finland
    Posts
    2,851
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Well, i made my own one, its working too:
    SCAR Code:
    function CountOptions(Texts: TStringArray): Integer;
    var
       B: TBox;
       TPA, TextTPA: TPointArray;
       aTPA: T2DPointArray;
       I, C, H, HH, ii: Integer;
       P: TPoint;
       Occurances: array [0..2] of TPointArray;
       SmallBoxes: TBoxArray;
    begin
      GetClientDimensions(B.X2, B.Y2);
      B.X1 := 0;
      B.Y1 := 0;
      SetLength(aTPA, 2);
      FindColorsTolerance(aTPA[0], 4409686, B.X1, B.Y1, B.X2, B.Y2, 0);
      FindColorsTolerance(aTPA[1], 4016722, B.X1, B.Y1, B.X2, B.Y2, 0);
      TPA := MergeATPA(aTPA);
      SetLength(aTPA, 0);
      If Length(TPA) < 10 Then
        Exit;
      B.X2 := 0;
      B.Y2 := 0;

      P := TPA[0];
      H := High(TPA);
      Dec(H);
      For I := 0 To H Do
        If TPA[i].X = TPA[I+1].X - 1 Then
        Begin
          If C > 5 Then
          Begin
            B.X1 := P.X;
            B.Y1 := P.Y;
            Break;
          End Else
            C := C + 1;
        End
        Else
        Begin
          P := TPA[I + 1];
          C := 0;
        End;
      If I = Length(TPA) Then
      Begin
        WriteLn('Choose Option Menu Getting Failed');
        Exit;
      End;
      InvertTPA(TPA);
      C := 0;
      P := TPA[0];
      H := High(TPA);
      Dec(H);
      For I := 0 To H Do
        If TPA[i].X = TPA[I+1].X + 1 Then
        Begin
          If C > 5 Then
          Begin
            B.X2 := P.X;
            B.Y2 := P.Y;
            Break;
          End Else
            C := C + 1;
        End Else
        Begin
          P := TPA[I + 1];
          C := 0;
        End;
      If I = Length(TPA) Then
      Begin
        WriteLn('Choose Option Menu Getting Failed');
        Exit;
      End;
     
    ///////////////////////////////////////
      SetLength(SmallBoxes, (B.y2 - B.y1)/15);
      for i := 0 to High(SmallBoxes) do
      begin
        SmallBoxes[i].x1 := B.x1;
        SmallBoxes[i].y1 := B.y1 + i * 15 + 3;
        SmallBoxes[i].x2 := B.x2;
        SmallBoxes[i].y2 := B.y1 + (i + 1) * 15 + 3;
      end;
     
      for ii := 0 to High(Texts) do
      begin
        TextTPA := LoadTextTPA(Texts[ii], UpChars, HH);
        for i := 0 to High(SmallBoxes) do
        begin
          FindColorsTolerance(Occurances[0], 1845035, SmallBoxes[i].X1, SmallBoxes[i].Y1 - 5, SmallBoxes[i].X2, SmallBoxes[i].Y2 + 5, 0);
          FindColorsTolerance(Occurances[1], clBlack, SmallBoxes[i].X1, SmallBoxes[i].Y1 - 5, SmallBoxes[i].X2, SmallBoxes[i].Y2 + 5, 0);
          FindColorsTolerance(Occurances[2], 6121839, SmallBoxes[i].X1, SmallBoxes[i].Y1 - 5, SmallBoxes[i].X2, SmallBoxes[i].Y2 + 5, 0);
          TPA := MergeATPA(Occurances);

          ClearDoubleTPA(TPA);
          TPA := ReturnPointsNotInTPA(TPA, SmallBoxes[i]);
          if High(TPA) < 1 then TPA := MergeATPA(Occurances);
          if FindTextTPAInTPA(HH, TextTPA, TPA, TPA) then
            Inc(result);
        end;
      end;
    end;

Thread Information

Users Browsing this Thread

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

Tags for this Thread

Posting Permissions

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