Results 1 to 5 of 5

Thread: MinEx and MaxEx- functions

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

    Default MinEx and MaxEx- functions

    Example: MinEx([6, 3, 0, 7]) returns 0
    SCAR Code:
    function MinEx(numbers: array of integer): integer;
    var
      i: integer;
    begin
      result:= numbers[0];
      for i:= 1 to high(numbers) do
      begin
       if (numbers[i] < result) then
        result:= numbers[i];
      end;
    end;

    Example: MaxEx([2, -1, 4, 8, 2]) returns 8
    SCAR Code:
    function MaxEx(numbers: array of integer): integer;
    var
      i: integer;
    begin
      result:= numbers[0];
      for i:= 1 to high(numbers) do
      begin
       if (numbers[i] > result) then
        result:= numbers[i];
      end;
    end;

    Max() and Min() only return the greater one from 2 numbers, these functions return it from how many numbers u want.

    I think this would make a great addition in SRL (comparing distances or levels, for example)
    In-Game example:
    SCAR Code:
    procedure TrainWeakestLevel;
    begin
     case MinEx([Players[CP].Level[1], Players[CP].Level[2], Players[CP].Level[3]) of
      Players[CP].Level[1]: SetFightMode(1);
      Players[CP].Level[2]: SetFightMode(2);
      Players[CP].Level[3]: SetFightMode(4);
     end;
    end;
    (Haha, TrainWeakestLevel wouldnt be a bad addition on its own either )

  2. #2
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

    Isn't there MinA and MaxA?



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

  3. #3
    Join Date
    Oct 2006
    Location
    ithurtsithurtsithurtsithurts
    Posts
    2,930
    Mentioned
    7 Post(s)
    Quoted
    135 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    Isn't there MinA and MaxA?
    It's AMin and AMax, but yes.

  4. #4
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Much quicker:
    SCAR Code:
    function MinEx(a: TIntegerArray; var where: integer): integer;
    begin
      Result := AMin(a);
      InIntArrayEx(a, where, Result);
    end;

    function MaxEx(a: TIntegerArray; var where: integer): integer;
    begin
      Result := AMax(a);
      InIntArrayEx(a, where, Result);
    end;

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

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Functions
    By lordsaturn in forum OSR Help
    Replies: 1
    Last Post: 08-13-2007, 10:12 PM

Posting Permissions

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