Results 1 to 14 of 14

Thread: TPA looping and error - help :S

  1. #1
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    TPA looping and error - help :S

    ok, this is my TPA for cutting the a yew tree. i have 2 problems with it, atm im getting an error saying:
    [Runtime Error] : Out Of Range in line 35 in script (i marked it with a [line35])

    and also, before when it was working it would continue looping through this procedure over and over even though i havent used any repeat in it..


    SCAR Code:
    function CutYew: Boolean;
    var
       x, y: integer;
       TPA: TpointArray;
       ATPA: T2DPointArray;
       i : integer;
       Colors: TIntegerArray;

    begin
      if(InFight) then Exit;
      Result := False;
      Colors := [2054219, 2582619, 4289678, 1660232, 1188897, 1660233, 2973012, 4621945];
      for i := 0 to 8 do
      begin
    [line35]    FindColorsSpiralTolerance(MSCX, MSCY, TPA, Colors[i], MSX1, MSY1, MSX2, MSY2, 7);
        if Length(TPA) = 0 then Continue;
        ATPA := SplitTPA(TPA, 44);
        for i := 0 to High(ATPA) do
        begin
          MiddleTPAEx(ATPA[i], x, y);
          SWait;
          MMouse(x, y, 3, 3);
          if IsUpText('Yew') then
          begin
            Mouse(x, y, 4, 4, True);
            SWait;
            WriteLn('Cutting Yew');
          end;
        end;
      end;
    end;
    Lance. Da. Pants.

  2. #2
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Its because you've put for
    SCAR Code:
    for i := 0 to 8 do

    When in fact you have 8 different colors, not 9, so it should be:

    SCAR Code:
    for i := 0 to 7 do

    EDIT: Because you start at 0 not 1, so its 0,1,2,3,4,5,6,7. Which is 8 colors, understand?

  3. #3
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    ohhh k thanks so much!

    Edit: erm that only fixed the error. my procedure is still looping continously. do i need to add a exit to make it stop? o.O
    Lance. Da. Pants.

  4. #4
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    add an exit ir break after the WriteLn. Also why not take advantage of the boolean and after mouse add Result := True; then at the end of the script go if reault then break; ?

    something along those lines, if you dont understand i can show you what i mean.
    “Ignorance, the root and the stem of every evil.”

  5. #5
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Yeah I get what Blumblebee means, what you want is to do something like this:
    SCAR Code:
    function CutYew: Boolean;
    var
       x, y: integer;
       TPA: TpointArray;
       ATPA: T2DPointArray;
       i : integer;
       Colors: TIntegerArray;
     
    begin
      if(InFight) then Exit;
      Result := False;
      Colors := [2054219, 2582619, 4289678, 1660232, 1188897, 1660233, 2973012, 4621945];
      for i := 0 to 8 do
      begin
    [line35]    FindColorsSpiralTolerance(MSCX, MSCY, TPA, Colors[i], MSX1, MSY1, MSX2, MSY2, 7);
        if Length(TPA) = 0 then Continue;
        ATPA := SplitTPA(TPA, 44);
        for i := 0 to High(ATPA) do
        begin
          MiddleTPAEx(ATPA[i], x, y);
          SWait;
          MMouse(x, y, 3, 3);
          Result := IsUpText('ew') then //can't use capital letters for IsUpText btw
          If Result then
          break; //breaks out of the loop here
          If Result then
          begin
            GetMousePos(x,y);
            Mouse(x, y, 4, 4, True);
            SWait;
            WriteLn('Cutting Yew');
          end;
          If not(Result) then
          WriteLN('Couldn'#39#' find the tree');
        end;
      end;
    end;

    So that it will break out of the to do loop if the uptext is what you require.

  6. #6
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    oh thanks bumblebee, i understand and it should work
    Lance. Da. Pants.

  7. #7
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    fixed...

    SCAR Code:
    function CutYew: Boolean;
    var
       x, y: integer;
       TPA: TpointArray;
       ATPA: T2DPointArray;
       i : integer;
       Colors: TIntegerArray;

    begin
      if (InFight) then Exit;
      Result := False;
      Colors := [2054219, 2582619, 4289678, 1660232, 1188897, 1660233, 2973012, 4621945];
      for i := 0 to 8 do
      begin
        FindColorsSpiralTolerance(MSCX, MSCY, TPA, Colors[i], MSX1, MSY1, MSX2, MSY2, 7);
        if Length(TPA) = 0 then Continue;
        ATPA := SplitTPA(TPA, 44);
        for i := 0 to High(ATPA) do
        begin
          MiddleTPAEx(ATPA[i], x, y);
          SWait;
          MMouse(x, y, 3, 3);
          Result := IsUpText('ew')//can't use capital letters for IsUpText btw
          If Result then
          begin
            GetMousePos(x,y);
            Mouse(x, y, 4, 4, True);
            SWait;
            WriteLn('Cutting Yew');
            Break;
          end;
          If not(Result) then
          WriteLN('Not a Yew');
        end;
      end;
    end;

  8. #8
    Join Date
    Jul 2008
    Location
    Canada
    Posts
    1,612
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    !! Lance you better credit the TPA, to who really made it, even if it sucked a bit...(creater-yarl know

  9. #9
    Join Date
    Feb 2007
    Location
    Alberta,Canada
    Posts
    2,358
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by mormonman View Post
    fixed...

    SCAR Code:
    Result := IsUpText('ew')//can't use capital letters for IsUpText btw
    You can use Capital letters for IsUpText, it just takes longer for scar to find capitals which is why lowercase letters are prefered.

    Edit: For the if not result, why not make that in the loop still, and if the result doesnt come back as true then call on Continue; thus making the loop restart?
    “Ignorance, the root and the stem of every evil.”

  10. #10
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    haha i put a {smarter child was here} above it xD though it seems that i will have to put a few more names above it now lol

    Edit:

    oh and Richard, sorry for excluding you from that post i must have writen it just a fraction of a moment after you cause i didnt see it. but umm i actualy got something very differant out of what bumble said, and it works though its probably messyer codeing than what you made.

    and also, what does break do? im still very new to srl. (my longevity lies)
    So far im useing Exit, to exit the procedure when a yew is clicked on, then i have a procedure to check if the txt is up for yew and it waits untill the txt is no longer up, I.E. the tree not there anymore. then it walks to the next tree and repeat the whole ordeal.
    Lance. Da. Pants.

  11. #11
    Join Date
    Dec 2007
    Location
    192.168.1.73
    Posts
    2,439
    Mentioned
    6 Post(s)
    Quoted
    119 Post(s)

    Default

    Break just basically breaks out of any loops that may be happening, normally used as a failsafe.

  12. #12
    Join Date
    Dec 2006
    Location
    Canada, BC
    Posts
    728
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Richard View Post
    Break just basically breaks out of any loops that may be happening, normally used as a failsafe.
    isnt that what Exit; does?
    Lance. Da. Pants.

  13. #13
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    Quote Originally Posted by lancerawks View Post
    isnt that what Exit; does?
    Exit quits a procedure.

  14. #14
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    SCAR Code:
    function CutYew: Boolean;
    var
       x, y: integer;
       TPA: TpointArray;
       ATPA: T2DPointArray;
       i : integer;
       Colors: TIntegerArray;
     
    begin
      if(InFight) then Exit;
      Result := False;
      Colors := [2054219, 2582619, 4289678, 1660232, 1188897, 1660233, 2973012, 4621945];
      for i := 0 to 7 do // Made this to 7
      begin
        FindColorsSpiralTolerance(MSCX, MSCY, TPA, Colors[i], MSX1, MSY1, MSX2, MSY2, 7);
        if Length(TPA) = 0 then Continue;
        ATPA := SplitTPA(TPA, 44);
        for i := 0 to High(ATPA) do
        begin
          MiddleTPAEx(ATPA[i], x, y);
          SWait;
          MMouse(x, y, 3, 3);
          if IsUpText('Yew') then
          begin
            Mouse(x, y, 4, 4, True);
            SWait;
            WriteLn('Cutting Yew');
            Result := True;
            Break; // Breaks first loop Could also use exit here.. but incase you want to add more to it, I just used two breaks :)
          end;
        if Result then Break;  // Breaks second loop
        end;
      end;
    end;

    =] Fully fixed.. AFAIK
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. looping problems
    By sink998 in forum OSR Help
    Replies: 6
    Last Post: 09-14-2008, 01:52 AM
  2. Looping for overnight run?
    By Petabanana in forum OSR Help
    Replies: 1
    Last Post: 03-03-2008, 03:21 AM
  3. Why does the response keep on looping?
    By Psychor in forum OSR Help
    Replies: 0
    Last Post: 11-12-2007, 05:10 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
  •