Results 1 to 20 of 20

Thread: IsChatBoxTextAnyLineMulti

  1. #1
    Join Date
    Dec 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default IsChatBoxTextAnyLineMulti

    Hello,

    The follow code takes multiple words and multiple colors to search in the chatbox.
    It will search all words in all colors.

    Simba Code:
    (*
    IsChatBoxTextAnyLineMulti
    ~~~~~~~~~~~~~~~~~~~~

    .. code-block:: pascal

        function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;

    Just like IsChatBoxTextAnyLine, only takes an array of text to search and an array of colors.
    Each text is searched in each color

    Example:

    .. code-block:: pascal

        if ( IsChatBoxTextAnyLineMulti( ['bot', 'other'], [16711680, 239]) ) then

    *)

    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j, tCounter, cCounter: Integer;
    begin
      tCounter := High(Text);
      cCounter := High(Colors);
      for i := 0 to tCounter do
        for j := 0 to cCounter do
          if ( IsChatBoxTextAnyLine(Text[i], Colors[j]) ) then
          begin
            Result := True;
            Exit;
          end;
    end;

  2. #2
    Join Date
    Oct 2011
    Location
    UK
    Posts
    1,322
    Mentioned
    2 Post(s)
    Quoted
    1 Post(s)

    Default

    Looks good, btw just wondering if you know...

    is there a reason not to just do this:
    Simba Code:
    for i := 0 to High(Text) do
        for j := 0 to High(Colors) do
    I have seen loads of scripts where people have done it like you do, is there a reason to?

  3. #3
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Instead of using tCounter and cCounter, use t and c, it'll save a few milliseconds

  4. #4
    Join Date
    Dec 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    In this case there isn't a reason to, I figure there could be if you would reuse the variable, then it wouldn't be affected by any function name changes.

    I only realised myself it isn't necessary untill I posted the code.

  5. #5
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    Looks good, btw just wondering if you know...

    is there a reason not to just do this:
    Simba Code:
    for i := 0 to High(Text) do
        for j := 0 to High(Colors) do
    I have seen loads of scripts where people have done it like you do, is there a reason to?
    Yes, it will make a function call every loop. Though a function call will not take that long, functions like this should be the fastest way possible.

    Quote Originally Posted by abu_jwka View Post
    Instead of using tCounter and cCounter, use t and c, it'll save a few milliseconds
    Are you sure? I thought that it didn't matter anymore, maybe that was in LAPE . I recommend using full names though, for the readability.

    edit:
    I just read what this actually does. There is no reason to speed it up. I do recommend to call freeze and unfreeze. This will make a significantly performance improvement:
    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          if ( IsChatBoxTextAnyLine(Text[i], Colors[j]) ) then
          begin
            Result := True;
            Exit;
          end;
      UnFreeze;
    end;
    Last edited by masterBB; 04-16-2012 at 06:46 PM.
    Working on: Tithe Farmer

  6. #6
    Join Date
    Feb 2012
    Location
    Somewhere, over the rainbow...
    Posts
    2,272
    Mentioned
    3 Post(s)
    Quoted
    45 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Are you sure? I thought that it didn't matter anymore, maybe that was in LAPE . I recommend using full names though, for the readability.
    I dunno I've ready many tutorials where they used one letter integers to represent Array Lengths and said it saves time...

  7. #7
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by abu_jwka View Post
    I dunno I've ready many tutorials where they used one letter integers to represent Array Lengths and said it saves time...
    Yeah, maybe that is pascalscript. I know in most other languages it doesn't matter. I hope lape doesn't got the same problem. Notice how I removed it entirely in the above code. Also it doesn't really matter, the function calls to the other chat box read function takes 99.99% of the time. The freeze will make a big difference though.
    Working on: Tithe Farmer

  8. #8
    Join Date
    Dec 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Yeah, maybe that is pascalscript. I know in most other languages it doesn't matter. I hope lape doesn't got the same problem. Notice how I removed it entirely in the above code. Also it doesn't really matter, the function calls to the other chat box read function takes 99.99% of the time. The freeze will make a big difference though.
    I do get an error if I add the freeze in text.simba:

    Simba Code:
    Error: Exception: Cannot get image target while frozen at line 832

    Edit: The error occurs in text.simba
    Last edited by mpd; 04-16-2012 at 07:03 PM.

  9. #9
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by mpd View Post
    I do get an error if I add the freeze in text.simba:

    Simba Code:
    Error: Exception: Cannot get image target while frozen at line 832
    Maybe it is only possible in pascal... I will look into it.
    Working on: Tithe Farmer

  10. #10
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    I don't know why it happens... It shouldn't. The idea of using freeze and unfreeze was that you will create a buffer from the screen. This buffer will be used multiple times, instead of getting the buffer again and again. Normally that will take a good amount of time with every color search. And though it works with the other color find function the OCR seems to have some troubles with it. The exception is raised by the following function in the input output manager:

    pascal Code:
    procedure TIOManager_Abstract.GetImageTarget(var idx: integer);
    begin
      if IsFrozen then
        raise Exception.Create('Cannot get image target while frozen');
      idx:= GetTargetIdx(image);
    end;

    I might have already lost you there. But I can't find a fix for it at this moment.
    Working on: Tithe Farmer

  11. #11
    Join Date
    Dec 2007
    Posts
    37
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I understand you perfectly fine and thank you for looking into this matter. I'll see if I can come up with a solution myself aswell.

    Edit:

    I understand why it throws the error: Whenever there's a text found, it results true and exits while leaving the screen frozen.

    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          if ( IsChatBoxTextAnyLine(Text[i], Colors[j]) ) then
          begin
            Result := True;
            UnFreeze;
            Exit;
          end;
      UnFreeze;
    end;
    Last edited by mpd; 04-16-2012 at 08:36 PM.

  12. #12
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by mpd View Post
    I understand you perfectly fine and thank you for looking into this matter. I'll see if I can come up with a solution myself aswell.
    Now I look into the color functions itself, I feel like an idiot. Though I do see some things that might improve performance, I'm not sure if it would make that much. I'm also fairly sure that it will be just a waste of time. I did find a double findcolortol method, so I might push that later, but that is not related to this suggestion

    edit:
    Nice you found the error . I'm already looking through the simba source for over an hour :P
    Working on: Tithe Farmer

  13. #13
    Join Date
    Aug 2007
    Location
    England
    Posts
    1,038
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Why don't you just do it like this ?

    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          Result := (IsChatBoxTextAnyLine(Text[i], Colors[j]));
      UnFreeze;
    end;
    Today is the first day of the rest of your life

  14. #14
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by Jakkle View Post
    Why don't you just do it like this ?

    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          Result := (IsChatBoxTextAnyLine(Text[i], Colors[j]));
      UnFreeze;
    end;
    Cause your code doesn't work. It needs to exit at the first found true. Let's say color 1 is true and color 2 is false. It will just set the result at false instead of true.
    Working on: Tithe Farmer

  15. #15
    Join Date
    Aug 2007
    Location
    England
    Posts
    1,038
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    Cause your code doesn't work. It needs to exit at the first found true. Let's say color 1 is true and color 2 is false. It will just set the result at false instead of true.
    Ah yeah I see the reason it's done like that now. Thanks
    Today is the first day of the rest of your life

  16. #16
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by Jakkle View Post
    Ah yeah I see the reason it's done like that now. Thanks
    In Lape it could look something like:
    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          if (Result := IsChatBoxTextAnyLine(Text[i], Colors[j])) then
            Break(2);
      UnFreeze;
    end;

    Can't wait till we dump pascalscript.
    Working on: Tithe Farmer

  17. #17
    Join Date
    Aug 2007
    Location
    England
    Posts
    1,038
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    In Lape it could look something like:
    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          if (Result := IsChatBoxTextAnyLine(Text[i], Colors[j])) then
            Break(2);
      UnFreeze;
    end;

    Can't wait till we dump pascalscript.
    Ah I see, looks better.
    What about this,
    [simba]
    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          if (IsChatBoxTextAnyLine(Text[i], Colors[j])) then
            Result := True
      UnFreeze;
    end;
    I was just thinking of how to make it shorter thats all
    Today is the first day of the rest of your life

  18. #18
    Join Date
    Oct 2006
    Location
    Netherlands
    Posts
    3,285
    Mentioned
    105 Post(s)
    Quoted
    494 Post(s)

    Default

    Quote Originally Posted by Jakkle View Post
    Ah I see, looks better.
    What about this,
    [simba]
    Simba Code:
    function IsChatBoxTextAnyLineMulti(Text: TStringArray; Colors: TIntegerArray): Boolean;
    var
      i, j: Integer;
    begin
      Freeze;
      for i := High(Text) downto 0 do
        for j := High(Colors) downto 0 do
          if (IsChatBoxTextAnyLine(Text[i], Colors[j])) then
            Result := True
      UnFreeze;
    end;
    I was just thinking of how to make it shorter thats all
    You just moved the problem one line .
    Working on: Tithe Farmer

  19. #19
    Join Date
    Aug 2007
    Location
    England
    Posts
    1,038
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    Quote Originally Posted by masterBB View Post
    You just moved the problem one line .
    Haha not thinking at all there
    Last edited by Jakkle; 04-17-2012 at 05:12 PM.
    Today is the first day of the rest of your life

  20. #20
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    Quote Originally Posted by putonajonny View Post
    Looks good, btw just wondering if you know...

    is there a reason not to just do this:
    Simba Code:
    for i := 0 to High(Text) do
        for j := 0 to High(Colors) do
    I have seen loads of scripts where people have done it like you do, is there a reason to?
    Supposedly "faster". Although the difference would be so insignificant, it doesn't really matter in this instance (if you are doing quite a bit of iterations, it may save at most 5ms).

    Quote Originally Posted by abu_jwka View Post
    Instead of using tCounter and cCounter, use t and c, it'll save a few milliseconds
    No it won't.
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

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
  •