Page 1 of 2 12 LastLast
Results 1 to 25 of 28

Thread: InArr();

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

    Default InArr();

    well, for those lazy people who dont want to use a certain type of InBlankArr(), here


    Rounds two: THanks to Naum
    SCAR Code:
    function InArrEx(Arr: TVariantArray; Any: Variant; Var Place : Integer): Boolean;
    var
      i: Integer;
    begin
      for i := 0 to high(Arr) do
        try
          result := Arr[i] = Any;      
          if result then
          begin
            Place := I;
            Exit;
          end;
        except
        end;
    end;

    Function InArr(Arr: TVariantArray; Any: Variant): Boolean;
    var
      spot: Integer;
    begin
      result := InArrEx(Arr, Any, spot);
    end;


    Original:
    SCAR Code:
    function InArr(Arr: TVariantArray; Any: Variant): Boolean;
    var
      i: Integer;
    begin
      for i := 0 to high(Arr) do
        try
          result := Arr[i] = Any;
          if result then exit;
        except
        end;
    end;

    I was reading Naums tut and thought "Oh no one has made just a general 'InArr'?"

    So I thought I'd try
    Took about two minutes.

    Example : writeln(InArr(['wat', 2, 'haf', 244, true], 2));
    Last edited by noidea; 08-21-2009 at 04:43 AM.
    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

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

    Default

    Also have an InArrEx:

    SCAR Code:
    function InArrEx(Arr: TVariantArray; Any: Variant; Var Place : Integer): Boolean;
    var
      i: Integer;
    begin
      for i := 0 to high(Arr) do
        try
          result := Arr[i] = Any;      
          if result then
          begin
            Place := I;
            Exit;
          end;
        except
        end;
    end;

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

    Default

    Done ^.^
    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

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

    Default

    I don't like the use of try except, does anyone know if it affects the speed/cpu usage/ram usage?
    I am sure there is some way to remove the try except

    Other than that: good job

  5. #5
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Ermm, try except and the other one (unless I think?) are all very low level functions, from what I remember. Like or/xor/not/blah blah blah. Not entirely sure, though.

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

    Default

    Quote Originally Posted by ian. View Post
    Ermm, try except and the other one (unless I think?) are all very low level functions, from what I remember. Like or/xor/not/blah blah blah. Not entirely sure, though.
    the try and except are for runtime errors.

    If you're Any is an Integer, and there is a string in the Arr, then it will produce a runtime error.
    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

  7. #7
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I know what they're for.. >_> He said that they're slow. I'm saying they're low level and aren't slow/don't use much RAM/anything like that.

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

    Default

    Quote Originally Posted by ian. View Post
    I know what they're for.. >_> He said that they're slow. I'm saying they're low level and aren't slow/don't use much RAM/anything like that.
    oh, sorry :x
    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

  9. #9
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by ian. View Post
    I know what they're for.. >_> He said that they're slow. I'm saying they're low level and aren't slow/don't use much RAM/anything like that.
    I don't know what you mean by "they're low level," but they're almost twice as slow as regular begin..end blocks.

  10. #10
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by bullzeye95 View Post
    I don't know what you mean by "they're low level," but they're almost twice as slow as regular begin..end blocks.
    I didn't wanna say low level functions/procedures, because I don't know the real name for them. And are begin..end blocks slow? I'm just trying to tell Zyt3x that try except isn't very slow. =X

  11. #11
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by ian. View Post
    I didn't wanna say low level functions/procedures, because I don't know the real name for them. And are begin..end blocks slow? I'm just trying to tell Zyt3x that try except isn't very slow. =X
    I'm not really sure if it's possible to test the speed of begin..end blocks :\

  12. #12
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Well in general you should be able to figure out if they're slow or fast.. I'd think..

  13. #13
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Well, if you tell me how, I'll test it

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

    Default

    Sooo, has any one experienced problems with the function?
    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

  15. #15
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Works good. ^^ I couldn't find any problems.

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

    Default

    I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like noidea's stuff
    Last edited by Naum; 08-21-2009 at 04:32 PM.

  17. #17
    Join Date
    Dec 2008
    Posts
    2,813
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like ian's stuff
    lolwut? =X

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

    Default

    Quote Originally Posted by ian. View Post
    lolwut? =X
    Because I luff you . Changed

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

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like noidea's stuff
    omfg <3 that would be like a wet dream.
    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

  20. #20
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by NaumanAkhlaQ View Post
    I'm thinking, why not scrap out all of srl and wizzyplugin's In(what ever)Arr/ex and replace it with something like noidea's stuff
    Because as far as I can tell, you can only pass TVariantArrays. You can't even typecast other array types to a TVariantArray; it will still give a runtime error.

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

    Default

    Quote Originally Posted by bullzeye95 View Post
    Because as far as I can tell, you can only pass TVariantArrays. You can't even typecast other array types to a TVariantArray; it will still give a runtime error.
    I'll test it first, btw I dig your sig.

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

    Default

    If the parameter requires a TVariantArray wouldn't trying to give a var defined as a TintegerArray or TStringArray for example result in a type mismatch error?

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

    Default

    Quote Originally Posted by ZephyrsFury View Post
    If the parameter requires a TVariantArray wouldn't trying to give a var defined as a TintegerArray or TStringArray for example result in a type mismatch error?
    That is correct.

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

    Default

    I just tested, and and it looks like it =\
    One could always change that TIntegerArray to a TVariant array
    but that could cause other problems in the long run =\
    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

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

    Default

    You could always ask Freddy to make an InArr function. I'm not sure how but using delphi you can make functions take undefined types (similar to how Swap() can swap any two variables as long as the types are the same). Perhaps you could do it in a plugin too although I'm not too sure.

Page 1 of 2 12 LastLast

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
  •