Results 1 to 15 of 15

Thread: function GetLength- similar to Length and GetArrayLength

  1. #1
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default function GetLength- similar to Length and GetArrayLength

    SCAR Code:
    function GetLength(arr: TpointArray): integer;
    var
      i, Length : integer;
    begin
      for i:=0 to High(arr) do
      begin
        Inc(Length);
      end;
      result := Length;
    end;

    you can change (arr: TPointArray) to another variable if you arent using TPointArray, e.g: (arr: T2DPointArray).

    test it:

    open SCAR, paste this and click start.
    SCAR Code:
    program New;
    var
      x,y : integer;
      TPA : TPointArray;
    function GetLength(arr:TpointArray): integer;
    var
      i, Length : integer;
    begin
      for i:=0 to High(arr) do
      begin
        Inc(Length);
      end;
      result := Length;
    end;
    begin
      FindColorsTolerance(TPA, 16777215, 365, 528, 365, 529, 1);
      Writeln(IntToStr(GetLength(TPA)))
      Writeln(IntToStr(Length(TPA)))
    end.
    the results will be the same.


  2. #2
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    But why did you make a function like this?

    There are Length and GetArrayLength which both are a lot faster than this

    Also, remember not to use a function name of SCAR (not SRL) as a global variable, since it overrides the function and can cause terrible things.

  3. #3
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    But why did you make a function like this?

    There are Length and GetArrayLength which both are a lot faster than this

    Also, remember not to use a function name of SCAR (not SRL) as a global variable, since it overrides the function and can cause terrible things.
    becouse i was bored, i know that Length and GetArrayLength are faster, i was testing my abilities.

    and the last thing, why can it cause terrible things?


  4. #4
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Hasn't your mommy ever told you about...

    A non-runtime error?

    -Oh my god! What is that?!

    SCAR Code:
    Program New;

    Var
       Length, I: Integer;
       
    begin
      For I := 1 To Length('string') Do
        Writeln('<0.o>');
    end.

  5. #5
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    Hasn't your mommy ever told you about...

    A non-runtime error?

    -Oh my god! What is that?!

    SCAR Code:
    Program New;

    Var
       Length, I: Integer;
       
    begin
      For I := 1 To Length('string') Do
        Writeln('<0.o>');
    end.
    they arent terrible things, runtime errors are terrible.


  6. #6
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    No they aren't if you don't get them

    a) Script right
    b) Use Try - Except ( - Final ) at dangerous areas.

  7. #7
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    No they aren't if you don't get them

    a) Script right
    b) Use Try - Except ( - Final ) at dangerous areas.
    im ok now.

    btw, im going to give you a cookie:


  8. #8
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Length(arr) would do, sorry but your's is pointless. :S
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  9. #9
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Negaal View Post
    Length(arr) would do, sorry but your's is pointless. :S
    yes, i tried that but it gave me this error:
    [Error] (2:24): colon (':') expected in script


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

    Default

    Then something was wrong, probably around that line... if you post it, I (or somebody else if they get here first) will fix it...

  11. #11
    Join Date
    Nov 2007
    Location
    Chile
    Posts
    1,901
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by bullzeye95 View Post
    Then something was wrong, probably around that line... if you post it, I (or somebody else if they get here first) will fix it...
    SCAR Code:
    function GetLength(x): integer;

    thats the error


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

    Default

    You should not overwrite the Length() function with a variable called length.
    Like this:

    SCAR Code:
    program New;

    var
       point:tpoint;
    begin
      point:=point(x, y);
    end.

    Causes type mismatches.

    Also, Length = High + Low + 1.



    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)

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

    Default

    Quote Originally Posted by Wizzup? View Post
    Also, Length = High + Low + 1.
    Length = High - Low + 1

  14. #14
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Cazax View Post
    SCAR Code:
    function GetLength(x): integer;

    thats the error
    It might be caused because of multi-dimensional array aswell, if you using that, then you have to say it's index aswell.
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

  15. #15
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Quote Originally Posted by Wizzup? View Post
    You should not overwrite the Length() function with a variable called length.
    Like this:

    SCAR Code:
    program New;

    var
       point:tpoint;
    begin
      point:=point(x, y);
    end.

    Causes type mismatches.

    Also, Length = High + Low + 1.

    Hey - you can't steal people's points like that!

    -

    Quote Originally Posted by n3ss3s View Post
    Hasn't your mommy ever told you about...

    A non-runtime error?

    -Oh my god! What is that?!

    SCAR Code:
    Program New;

    Var
       Length, I: Integer;
       
    begin
      For I := 1 To Length('string') Do
        Writeln('<0.o>');
    end.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. As I Lay Dying (And Similar Bands)
    By YoHoJo in forum Music, Movies and TV
    Replies: 6
    Last Post: 03-14-2008, 06:39 AM
  2. Awesome MMORPG Game Similar/Better than RS
    By Saint in forum Misc. Links and Programs
    Replies: 3
    Last Post: 09-21-2007, 01:00 AM
  3. Array Problem!!! Won't call getarraylength
    By botmaster in forum OSR Help
    Replies: 5
    Last Post: 12-26-2006, 09:17 PM
  4. [GAME] ~~Paintball~~( Similar to Linerider)
    By drowningtrout in forum Misc. Links and Programs
    Replies: 2
    Last Post: 11-20-2006, 10:58 AM

Posting Permissions

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