Results 1 to 4 of 4

Thread: Out of Range?

  1. #1
    Join Date
    Sep 2008
    Posts
    241
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default Out of Range?

    What is wrong with this procedure?

    Code:
     
    program New; {.Include SRL\SRL.scar} procedure LookInterested(duration: Integer); var Colors: array of integer; cx, cy, cw, ch, c1, c2, start: Integer; begin GetClientDimensions(cw, ch); c1 := GetColor(RandomRange(1, cw), RandomRange(1, ch)); c2 := GetColor(RandomRange(1, cw), RandomRange(1, ch)); MarkTime(start); while (TimeFromMark(start) - 9000 < duration) do begin if (c1 > 10000) then Colors[GetArrayLength(Colors) - 1] := c1; if (c2 < 10000) then Colors[GetArrayLength(Colors) - 1] := c2; c1 := GetColor(RandomRange(1, cw), RandomRange(1, ch)); c2 := GetColor(RandomRange(1, cw), RandomRange(1, ch)); end; while (TimeFromMark(start) < duration) do begin FindColorTolerance(cx, cy, Colors[RandomRange(0, GetArrayLength(Colors) - 1)], 0, 0, cw, ch, 10); MMouse(cx, cy, RandomRange(1, 3), RandomRange(1, 3)); end; end; begin LookInterested(10000); end.

    It says some kind of out of range exception stuff...

    Any help?
    Last edited by Blender; 06-17-2009 at 09:05 AM.
    PM me if you need any help with math.
    I can try to help you with anything!


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

    Default

    You did not setlength on Colors.

    SCAR Code:
    SetLength(Colors, {enter array length});

    Basically when you did Colors[GetArrayLength(Colors) - 1], its substracting 1 from 0, making it go into negatives.

    GetArrayLength(Colors) = 0 ~ Since no length is set.



    ~NS

  3. #3
    Join Date
    Sep 2008
    Posts
    241
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Oh, thanks!

    What if colors has a variable length?
    PM me if you need any help with math.
    I can try to help you with anything!


  4. #4
    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 xXxBlender3DxXx View Post
    Oh, thanks!

    What if colors has a variable length?
    Then use the variable when setting the length...



    ~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
  •