Results 1 to 3 of 3

Thread: Out of global vars

  1. #1
    Join Date
    Dec 2011
    Location
    The Netherlands
    Posts
    1,631
    Mentioned
    47 Post(s)
    Quoted
    254 Post(s)

    Default Out of global vars

    Simba Code:
    function RopeSwing: Boolean;
    var
      X, Y, P, i: Integer;
      SwingCl: TPointArray;
      SwingClSplit: Array of TPointArray;

    begin
      ColorToleranceSpeed(2);
      SetColorspeed2Modifiers(0.12, 0.57);
      if FindColorsSpiralTolerance(X, Y, SwingCl, 663074, MSX1, MSY1, MSX2, MSY2, 5) then
        begin
          SplitTPAExWrap(SwingCl, 1, 1, SwingClSplit);

          if Debug then
            begin
              SMART_ClearCanvas;
              SMART_DrawDotsEx(True, SwingCl, clYellow); // Both swings
              SMART_DrawBoxes(False, [GetTPABounds(SwingCl)], clAqua); // TPA Box
              SMART_DrawBoxes(False, [GetTPABounds(SwingClSplit[0]), GetTPABounds(SwingClSplit[1])], clGreen); // ATPA boxes
              SMART_DrawCircle(False, MiddleTPA(SwingClSplit[0]), 2, True, clRed); // Left Swing middle
              SMART_DrawCircle(False, MiddleTPA(SwingClSplit[1]), 2, True, clRed); // Right Swing middle
              SMART_DrawBoxes(False, [IntToBox(GetTPABounds(SwingClSplit[0]).X1, 3 + GetTPABounds(SwingClSplit[0]).Y1, GetTPABounds(SwingClSplit[0]).X2, GetTPABounds(SwingClSplit[0]).Y1 + (GetTPABounds(SwingClSplit[0]).Y2 - GetTPABounds(SwingClSplit[0]).Y1)/10)], clRed); // Box on top of swing #1
              SMART_DrawBoxes(False, [IntToBox(GetTPABounds(SwingClSplit[1]).X1, 3 + GetTPABounds(SwingClSplit[1]).Y1, GetTPABounds(SwingClSplit[1]).X2, GetTPABounds(SwingClSplit[1]).Y1 + (GetTPABounds(SwingClSplit[1]).Y2 - GetTPABounds(SwingClSplit[1]).Y1)/10)], clRed); // Box on top of swing #2
              WriteLn('SwingClSplit[0] length: '+IntToStr(High(SwingClSplit[0]))+'');
              WriteLn('SwingClSplit[1] length: '+IntToStr(High(SwingClSplit[1]))+'');
              WriteLn('Rope #1 length: '+IntToStr((GetTPABounds(SwingClSplit[0]).Y2 - GetTPABounds(SwingClSplit[0]).Y1))+'');
              WriteLn('Rope #2 length: '+IntToStr((GetTPABounds(SwingClSplit[1]).Y2 - GetTPABounds(SwingClSplit[1]).Y1))+'');
           end;

          if (GetTPABounds(SwingClSplit[0]).Y2 - GetTPABounds(SwingClSplit[0]).Y1)<100 then
            begin
              case Random(4) of
                0: begin
                     P := RandomRange(Low(SwingClSplit[0]), High(SwingClSplit[0]));
                     MMouse(SwingClSplit[0][P].X, SwingClSplit[0][P].Y, 0, 0); // Random spot on rope 1
                   end;
                1: begin
                     P := RandomRange(Low(SwingClSplit[1]), High(SwingClSplit[1]));
                     MMouse(SwingClSplit[1][P].X, SwingClSplit[1][P].Y, 0, 0); // Random spot on rope 2
                   end;
                2: Mousebox(GetTPABounds(SwingClSplit[0]).X1, GetTPABounds(SwingClSplit[0]).Y1, GetTPABounds(SwingClSplit[0]).X2, GetTPABounds(SwingClSplit[0]).Y1 + (GetTPABounds(SwingClSplit[0]).Y2 - GetTPABounds(SwingClSplit[0]).Y1)/10, 2); // Random spot in the box of rope 1
                3: Mousebox(GetTPABounds(SwingClSplit[1]).X1, GetTPABounds(SwingClSplit[1]).Y1, GetTPABounds(SwingClSplit[1]).X2, GetTPABounds(SwingClSplit[1]).Y1 + (GetTPABounds(SwingClSplit[1]).Y2 - GetTPABounds(SwingClSplit[1]).Y1)/10, 2); // Random spot in the box of rope 2
              end;
              Result:=True;
            end else
            begin
              for i:=0 to 1 do
                begin
                  if ((GetTPABounds(SwingClSplit[i]).Y2 - GetTPABounds(SwingClSplit[i]).Y1)<90) then
                    begin
                      case Random(2) of
                        0: begin
                             P := RandomRange(Low(SwingClSplit[i]), High(SwingClSplit[i]));
                             MMouse(SwingClSplit[i][P].X, SwingClSplit[i][P].Y, 0, 0); // Random spot on rope 1
                           end;
                        1: Mousebox(GetTPABounds(SwingClSplit[i]).X1, GetTPABounds(SwingClSplit[i]).Y1, GetTPABounds(SwingClSplit[i]).X2, GetTPABounds(SwingClSplit[i]).Y1 + (GetTPABounds(SwingClSplit[i]).Y2 - GetTPABounds(SwingClSplit[i]).Y1)/10, 2); // Random spot in the box of rope 1
                      end;
                      Result:=True;
                    end;
                end;
            end;
        end;
    end;

    It compiles but gives me an error
    Simba Code:
    Error: Out of Global Vars range at line 69

    Line 69:
    Simba Code:
    if (GetTPABounds(SwingClSplit[0]).Y2 - GetTPABounds(SwingClSplit[0]).Y1)<100 then

    I don't understand why it results in an error because this works fine:
    Simba Code:
    WriteLn('Rope #1 length: '+IntToStr((GetTPABounds(SwingClSplit[0]).Y2 - GetTPABounds(SwingClSplit[0]).Y1))+'');
              WriteLn('Rope #2 length: '+IntToStr((GetTPABounds(SwingClSplit[1]).Y2 - GetTPABounds(SwingClSplit[1]).Y1))+'');
    Result:
    Simba Code:
    Rope #1 length: 83
    Rope #2 length: 73

    Oh yeah this is what it does

    Draws some graphics on the screen at the Barbarian Outpost agility course.
    I need to know what the length of the rope is to know if it's in use or not.

    EDIT:
    This fixes the problem so I guess I have to many undeclared variables or something?
    Simba Code:
    Rope1Length := (GetTPABounds(SwingClSplit[0]).Y2 - GetTPABounds(SwingClSplit[0]).Y1);
          Rope2Length := (GetTPABounds(SwingClSplit[1]).Y2 - GetTPABounds(SwingClSplit[1]).Y1);

          if (Rope1Length < 100) and (Rope2Length < 100) then
    Last edited by J J; 05-26-2012 at 06:49 PM.

    Script source code available here: Github

  2. #2
    Join Date
    Nov 2011
    Posts
    1,532
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    I know this is not really helping, but have you considered just clicking it and only if it says it's in use, then you do something about it?
    Current activity: Recovering from vacation
    - Nulla pars vitae vacare officio potest -
    SRL membership? Can I buy that?
    Scripts - AGS - SWF - WAR - EMS - W100S-EM
    If you need scripting help, you can pm me. Remember, if you need help you have to ask for it properly though

  3. #3
    Join Date
    Oct 2011
    Posts
    805
    Mentioned
    21 Post(s)
    Quoted
    152 Post(s)

    Default

    Optimalisation :
    You torment your CPU calling this function unnecessarily several times:

    Simba Code:
    GetTPABounds(SwingClSplit[i])

    It's much more effective ,if you assign result to variable ,if you are going to use it more then two times.

    Simba Code:
    tempBox := GetTPABounds(SwingClSplit[i])


    I don't guarantee it will help with error ,but I suspect this error has something to do with memory stack.

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
  •