Results 1 to 10 of 10

Thread: Color.scar ColorsInBox();

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

    Default Color.scar ColorsInBox();

    Pretty simple but I have used it on numerous occasions so I thought I may as well share:
    SCAR Code:
    {*******************************************************************************
    function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer;): Boolean;
    By: NCDS & Nava2
    Description:Returns true if "Color" is found in box (x1, y1), (x2, y2).
    *******************************************************************************}

    function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
    var
      tia: TIntegerArray; i, o: Integer;
    begin
      o := 0;
      tia := GetColorsBox(x1, y1, x2, y2, True);
      clearSameIntegers(tia);
      clearSameIntegers(color);
      for i := High(Color) downto 0 do
        if InIntArray(tia, Color[i]) then
          Inc(o);
      Result := (o = Length(Color));
    end;

    Any thoughts on this?
    Last edited by NCDS; 02-11-2010 at 07:47 AM.

  2. #2
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Really necessary? It's just FindColor/FindColors without the variables..

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

    Default

    Quote Originally Posted by i luffs yeww View Post
    Really necessary? It's just FindColor/FindColors without the variables..
    Hmm..I guess your right lol. Honestly, in all my time of using this, I never thought of it like that.

    I always normally used it for location checks and such as a "line saver"

  4. #4
    Join Date
    Jan 2008
    Location
    NC, USA.
    Posts
    4,429
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    I like it
    Could be used in lots of cases, such as using a blacklist if searching for colours.
    Quote Originally Posted by irc
    [00:55:29] < Guest3097> I lol at how BenLand100 has become noidea
    [01:07:40] <@BenLand100> i'm not noidea i'm
    [01:07:44] -!- BenLand100 is now known as BenLand42-
    [01:07:46] <@BenLand42-> shit
    [01:07:49] -!- BenLand42- is now known as BenLand420
    [01:07:50] <@BenLand420> YEA

  5. #5
    Join Date
    Jan 2010
    Posts
    5,227
    Mentioned
    6 Post(s)
    Quoted
    60 Post(s)

    Default

    Well since it's essentially the same thing as FindColors, you could just do something like

    SCAR Code:
    function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
    var
      x, y: Integer;
    begin
      Result := FindColors(x, y, [Color], x1, y1, x2, y2);
    end;

    Or whatever the params are.. I know it's basically the same thing..

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

    Default

    SCAR Code:
    {*******************************************************************************
    function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer;): Boolean;
    By: NCDS
    Description:Returns true if "Color" is found in box (x1, y1), (x2, y2).
    *******************************************************************************}

    function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
    var
      tia: TIntegerArray; i, o: Integer;
    begin
      o := 0;
      tia := GetColorsBox(x1, y1, x2, y2, True);
      clearSameIntegers(tia);
      clearSameIntegers(color);
      for i := High(Color) downto 0 do
        if InIntArray(tia, Color[i]) then
          Inc(o);
      Result := (o = Length(Color));
    end;
    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

  7. #7
    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
    SCAR Code:
    {*******************************************************************************
    function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer;): Boolean;
    By: NCDS
    Description:Returns true if "Color" is found in box (x1, y1), (x2, y2).
    *******************************************************************************}

    function ColorsInBox(Color: TIntegerArray; x1, y1, x2, y2: Integer): Boolean;
    var
      tia: TIntegerArray; i, o: Integer;
    begin
      o := 0;
      tia := GetColorsBox(x1, y1, x2, y2, True);
      clearSameIntegers(tia);
      clearSameIntegers(color);
      for i := High(Color) downto 0 do
        if InIntArray(tia, Color[i]) then
          Inc(o);
      Result := (o = Length(Color));
    end;
    That way looks nice

    Out of curiosity though, why for..downto..do instead of for..to..do?

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

    Default

    In freepascal, downto calculates the High() value and it becomes constant, then the 0 is left.

    As apposed to the regular where 0 is constant and High() is calculated every time. Small optimization for when order doesn't really matter.
    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

  9. #9
    Join Date
    Jan 2007
    Posts
    8,876
    Mentioned
    123 Post(s)
    Quoted
    327 Post(s)

    Default

    Quote Originally Posted by Nava2 View Post
    In freepascal, downto calculates the High() value and it becomes constant, then the 0 is left.

    As apposed to the regular where 0 is constant and High() is calculated every time. Small optimization for when order doesn't really matter.
    Oh, wow. I didn't know that
    Much easier than making a own variable for High() lol

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

    Default

    Quote Originally Posted by Zyt3x View Post
    Oh, wow. I didn't know that
    Much easier than making a own variable for High() lol
    I don't know if pascal script is smart enough for that though.
    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

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
  •