SRL Archive - OSR Help

Out of global vars


J J

2012-05-26 14:44:54

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
Error: Out of Global Vars range at line 69

Line 69:
  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:
          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:
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?
      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

Er1k

2012-05-27 11:06:24

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?

bg5

2012-05-27 12:27:44

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

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.

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.