Results 1 to 18 of 18

Thread: IsChatBoxTextLines

  1. #1
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default IsChatBoxTextLines

    This is just a small change from Zeph's 'IsChatBoxTextAnyLine'. I only added a couple Parameter's but I find it pretty useful.

    SCAR Code:
    {*******************************************************************************
    function IsChatBoxTextAnyLine(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    By: ZephyrsFury
    Description: Returns true if Text with colour TextCol is found between 'Line1'
    and 'Line2'.
    *******************************************************************************}

    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      II: Integer;
    begin
      Result := True;
      for II := Line2 downto Line1 do
        if (FindChatBoxText(Text, II, TextCol)) then
          Exit;
      Result := False;
    end;

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

    Default

    Could you post the original?
    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

  3. #3
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    Could you post the original?
    SCAR Code:
    {*******************************************************************************
    function IsChatBoxTextAnyLine(Text: string; TextCol: Integer): Boolean;
    By: ZephyrsFury
    Description: Returns true if Text with colour TextCol is found anywhere in the
      chat box.
    *******************************************************************************}

    function IsChatBoxTextAnyLine(Text: string; TextCol: Integer): Boolean;
    var
      II: Integer;
    begin
      Result := True;
      for II := 8 downto 1 do
        if (FindChatBoxText(Text, II, TextCol)) then
          Exit;
      Result := False;
    end;

    Btw, nice new avvy

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

    Default

    Added. Thanks.

  5. #5
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You should add in a Max and Min check, just as a fool-proof failsafe :P

    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      II: Integer;
    begin
      Result := True;
      for II := Max(Line1, Line2) downto Min(Line1, Line2) do
        if (FindChatBoxText(Text, II, TextCol)) then
          Exit;
      Result := False;
    end;



    ~NS

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

    Default

    Quote Originally Posted by Nadeem View Post
    You should add in a Max and Min check, just as a fool-proof failsafe :P

    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      II: Integer;
    begin
      Result := True;
      for II := Max(Line1, Line2) downto Min(Line1, Line2) do
        if (FindChatBoxText(Text, II, TextCol)) then
          Exit;
      Result := False;
    end;



    ~NS
    Got that

  7. #7
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol IDK why, but im starting to get obsession for shortening functions today...
    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      I: Integer;
    begin
      for I := Max(Line1, Line2) downto Min(Line1, Line2) do
        Result := FindChatBoxText(Text, I, TextCol);
        if Result then Exit;
    end;


    And I also made this one to return the Line number that text is present at:
    SCAR Code:
    function IsChatBoxTextLines(Text: string; var L: Integer; L1, L2, Col: Integer): Boolean;
    begin
      for L := Max(L1, L2) downto Min(L1, L2) do
        Result := FindChatBoxText(Text, L, TextCol);
        if Result then Exit;
    end;



    ~NS

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

    Default

    I want to beat you :

    SCAR Code:
    function IsChatBoxTextLines(Text: string; var L: Integer; L1, L2, Col: Integer): Boolean;
    begin
      for L := Max(L1, L2) downto Min(L1, L2) do
        Result := FindChatBoxText(Text, L, TextCol);
    end;

  9. #9
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol, I like it Although if you do not exit on the line it was True at, it'll return the wrong line number! Cuz what I did was, declare var L: Integer and at the same time using that return value as the loop's decreasing value :P



    ~NS

  10. #10
    Join Date
    Oct 2007
    Location
    #srl
    Posts
    6,102
    Mentioned
    39 Post(s)
    Quoted
    62 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    Added. Thanks.
    Happy to help

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

    Default

    Quote Originally Posted by Nadeem View Post
    lol IDK why, but im starting to get obsession for shortening functions today...
    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      I: Integer;
    begin
      for I := Max(Line1, Line2) downto Min(Line1, Line2) do
        Result := FindChatBoxText(Text, I, TextCol);
        if Result then Exit;
    end;


    And I also made this one to return the Line number that text is present at:
    SCAR Code:
    function IsChatBoxTextLines(Text: string; var L: Integer; L1, L2, Col: Integer): Boolean;
    begin
      for L := Max(L1, L2) downto Min(L1, L2) do
        Result := FindChatBoxText(Text, L, TextCol);
        if Result then Exit;
    end;



    ~NS
    You're missing a set of begin and ends.

    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      I: Integer;
    begin
      for I := Max(Line1, Line2) downto Min(Line1, Line2) do
      begin
        Result := FindChatBoxText(Text, I, TextCol);
        if Result then Exit;
      end;
    end;

  12. #12
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by ZephyrsFury View Post
    You're missing a set of begin and ends.

    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      I: Integer;
    begin
      for I := Max(Line1, Line2) downto Min(Line1, Line2) do
      begin
        Result := FindChatBoxText(Text, I, TextCol);
        if Result then Exit;
      end;
    end;
    It works besides the begin end;, doesn't it? But dun matter :P As long as it works, its all good.



    ~NS

  13. #13
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    you didnt have it in the begin end nest so it would not exit until it went through all the lines, whilst zephs (with the begin end nest) exits as soon as it sees the result, saving some time both work, just Zephs is a bit more efficient.
    “Ignorance, the root and the stem of every evil.”

  14. #14
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Awesome Never knew that!



    ~NS

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

    Default

    Quote Originally Posted by Blumblebee View Post
    you didnt have it in the begin end nest so it would not exit until it went through all the lines, whilst zephs (with the begin end nest) exits as soon as it sees the result, saving some time both work, just Zephs is a bit more efficient.
    Well actually it wouldn't work if you don't exit cos say for example Lines are from 1 to 8, it would search from line 8 going downto 1. If it found the text on line 4 it would set Result to True. If you exit at this point Result would remain true. However if you didn't it would keep going to line 3, 2, 1 and would set Result back to False again if the text isn't found.

  16. #16
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    orite forgot that haha sorry.
    “Ignorance, the root and the stem of every evil.”

  17. #17
    Join Date
    Feb 2006
    Location
    Helsinki, Finland
    Posts
    1,395
    Mentioned
    30 Post(s)
    Quoted
    107 Post(s)

    Default

    Guys, don't forget that... Sometimes a code with lower amount of lines is definitely not better than a code with higher amount of lines.

    I am pointing out to speed now, it matters much more. Every single ms matters!

    Here is a great little example:

    SCAR Code:
    var
      i, tmr, x, h: Integer;
      TSA: TStringArray;
     
    begin
      SetArrayLength(TSA, 10000000);
      tmr:= GetSystemTime;
      for i:= 0 to High(TSA) do
        Inc(x);
      WriteLn('Method A: X increased from 0 to ' + IntToStr(x) + ' (took ' + IntToStr(GetSystemTime - tmr) + 'ms.)');
      x:= 0;
      tmr:= GetSystemTime;
      h:= High(TSA);
      for i:= 0 to h do
        Inc(x);
      WriteLn('Method B: X increased from 0 to ' + IntToStr(x) + ' (took ' + IntToStr(GetSystemTime - tmr) + 'ms.)');
      SetArrayLength(TSA, 0);
    end.

    Now, the "IsChatBoxTextLines" function (that ZephyrsFury fixed), would be faster with higher amount of lines...

    Old:

    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      i: Integer;
    begin
      for i:= Max(Line1, Line2) downto Min(Line1, Line2) do
      begin
        Result:= FindChatBoxText(Text, i, TextCol);
        if(Result)then
          Exit;
      end;
    end;

    New:

    SCAR Code:
    function IsChatBoxTextLines(Text: string; Line1, Line2, TextCol: Integer): Boolean;
    var
      i, tmpMx, tmpMn: Integer;
    begin
      tmpMn:= Min(Line1, Line2);
      tmpMx:= Max(Line1, Line2);
      for i:= tmpMx downto tmpMn do
      begin
        Result:= FindChatBoxText(Text, i, TextCol);
        if(Result)then
          Exit;
      end;
    end;

    I myself got this lesson from Ron, and I am so glad I did. It probably doesn't matter so much with small projects, but when you'll get around bigger projects in SCAR, you'll definitely want to get around maximum speeds.

    -Jani

  18. #18
    Join Date
    Dec 2008
    Location
    In a galaxy far, far away...
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    lol yes, I know about that too, but never used it because we are only dealing with a maximum number of 8 lines so the at most you can save is probably 1ms? maybe it won't even make a difference :P But nevertheless it is a good strategy for larger loops.



    ~NS

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
  •