Results 1 to 3 of 3

Thread: Out of Range Help

  1. #1
    Join Date
    Oct 2007
    Location
    http://ushort.us/oqmd65
    Posts
    2,605
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default Out of Range Help

    SCAR Code:
    Function Tileisme:TIntegerArray;
    var
      Pig : UID;
      ItemTempPoint :TpointArray;
    begin
      setlength(Result,0);
      for D := 0 to high(You) do
      begin
        setlength(Result,high(You));
        Pig := GetObjectAt(You[D].x,You[D].y);
        ItemTempPoint := GetGroundItems(You[D].x,You[D].y);
        //writeln(Pig.objType);
        //writeln(inttostr(You[D].x)+','+inttostr(You[D].y));
        for I := 0 to High(ItemTempPoint) do
          writeln(ItemTempPoint[I].x);
        result[D] := 0;    //330 --------------------------- This Line
        if(Pig.objType=Be.setupid)then
          result[D] := 1;
      end;
    end;
    Result[D] := 0. I dont get it. I set the length right didn't I???
    I do visit every 2-6 months

  2. #2
    Join Date
    Jan 2007
    Location
    Nomming bits in your RAM
    Posts
    385
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    SetLength(x) sets the length of an array so that elements [0..x-1] are usuable.

    Try:
    SCAR Code:
    setlength(Result,Length(You));
    instead of
    SCAR Code:
    setlength(Result,high(You));

    Hope this helps!
    ~Macro_FTW
    Current Project: Catching up. XD. Potentially back for the summer, depending on how things go.

  3. #3
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    Just as an extra point, you should set the length outside the loop (before hand) as you're just running duplicate code and High() + 1 can be used in place of Length if you prefer uniform uses of stuff like that (I know some people only use Inc() or only use x := x + 1 and stuff like that).
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

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
  •