SRL Archive - OSR Help

Out of Global Vars range?


Troll

2011-07-21 06:31:06

Ok so it summer and im trying to write my first script again, and i think ill finish it this time as i have a lot of time but i have an error and need help :(

I get

New window: 19071850
[Hint] (106:10): Variable 'Result' never used at line 105
[Hint] C:\Simba\Includes\SRL/SRL/core/SRLlog.scar(17:3): Variable 'THEFILE' never used at line 16
Compiled succesfully in 998 ms.
SRL Compiled in 31 msec
Error: Out of Global Vars range at line 72
The following DTMs were not freed: [SRL - Lamp bitmap, 1]
The following bitmaps were not freed: [SRL - Mod bitmap, SRL - Admin bitmap]
and the script is


program new;
{$i SRL/SRL.scar}

Type
MonsterInfo = Record // so that i can add more later
MonName : String;
SecoundName : String; // so if a monster in the same room has same colour
MonColour : Integer;
MonSat : Extended;
MonHue : Extended;
MonToll : Integer;
End;

Function SetMonster(TheName:String; Which:Integer):MonsterInfo;
Begin

Case TheName Of

'zombie':Begin
Case Which Of
1:
With Result Do
Begin
MonName := 'Zombie';
SecoundName := 'Gaint rat';
MonColour := 3757940;
MonSat := 0.46;
MonHue := 0.07;
MonToll := 13;
End;
2:
With Result Do
Begin
MonName := 'Zombie';
SecoundName := 'GaintRat';
MonColour := 5198163;
MonSat := 0.02;
MonHue := 0.50;
MonToll := 17;
End;
3:
With Result Do
MonName := 'False';
End;
End;

End;

End;


Function FindMonster(TheName:String):Boolean;
Var
x,y,a,i:Integer;
TheTPA:TPointArray;
ATPA: TPointArrayArray;
Click:TPoint;
Begin

If Not LoggedIn Then Exit;

{
Name1 := SetMonster(TheName).MonName;
Name2 := SetMonster(TheName).SecoundName;
}
SetColorToleranceSpeed(2);

a := 1;

Repeat
SetColorspeed2Modifiers(SetMonster(TheName,a).MonHue,SetMonster(TheName,a).MonSat); //as the colour can change
If FindColorsSpiralTolerance(x,y,TheTPA,SetMonster(TheName,a).MonColour,MSX1,MSY1,MSX2,MSY2,SetMonster(TheName,a).MonToll) Then
If Length(TheTPA)>1 Then
Begin
ATPA := TPAtoATPAEx(TheTPA,3,3);
For I:= 0 to High(ATPA) Do
Begin
Click :=MiddleTPA(ATPA[I]);
MMouse(Click.x,click.y,RandomRange(-3,3),RandomRange(-3,3));
If (IsUpText(SetMonster(TheName,a).MonName) or IsUpText(SetMonster(TheName,a).SecoundName)) Then
Begin
GetMousePos(x,y);
If Random(20) = 5 Then
Begin
Mouse(x,y,0,0,False);
If ChooseOption('Attack') Then
Begin
Result := True;
writeln('Found and click monster');
Exit;
End Else Begin
Mouse(x,y,0,0,True);
writeln('Found and clicked monster');
Result := True;
Exit;
End;
End;
End;
End;
End;
Inc(A);
Until(False);
End;

Function Fighting:Boolean;
Begin
{
Check for HP bar

Check XP

}

End;




begin
SetupSRL;
ActivateClient;
FindMonster('zombie');
end.

Thanks for any help and your time :D Your all great here

Coh3n

2011-07-21 06:48:33

Instead of calling SetMonster all those times, create a new variable! :)

var
monster: MonsterInfo;
begin
// blah blah..

monster := SetMonster(theName, a);
repeat
SetColorspeed2Modifiers(monster.MonHue, monster.MonSat);
// apply to the rest of the setMonster calls
end;
I bet that gets rid of your error.

Dgby714

2011-07-21 06:59:21

From: Coh3n
Instead of calling SetMonster all those times, create a new variable! :)

var
monster: MonsterInfo;
begin
// blah blah..

monster := SetMonster(theName, a);
repeat
SetColorspeed2Modifiers(monster.MonHue, monster.MonSat);
// apply to the rest of the setMonster calls
end;
I bet that gets rid of your error.

"a" changes.

Coh3n

2011-07-21 07:01:58

Then set "monster" after "a" is reset, or at the beginning of the loop.

Troll

2011-07-21 07:05:29

From: Coh3n
Instead of calling SetMonster all those times, create a new variable! :)

var
monster: MonsterInfo;
begin
// blah blah..

monster := SetMonster(theName, a);
repeat
SetColorspeed2Modifiers(monster.MonHue, monster.MonSat);
// apply to the rest of the setMonster calls
end;
I bet that gets rid of your error.


Thanks ive done that and it works, your great :D Also i love MSI ;)

From: Dgby714
"a" changes.

Yeah ive put the (monster := setmonster) in the loop

Thanks your both great :)

Dgby714

2011-07-21 07:08:09

From: Troll
Thanks ive done that and it works, your great :D Also i love MSI ;)


Yeah ive put the (monster := setmonster) in the loop

Thanks your both great :)


You're going to love the more "advanced" features of Lape/Titan (They both have it) would make this a lot more "elegant".

Coh3n

2011-07-21 07:13:12

Glad it worked; although, I still don't know why it throws an error. >.<

Troll

2011-07-21 07:23:26

From: Dgby714
You're going to love the more "advanced" features of Lape/Titan (They both have it) would make this a lot more "elegant".


Umm what is lape/Titan

Coh3n

2011-07-21 07:24:37

From: Troll
Umm what is lape/Titan
Lape a Pascal Script alternative that Nielsie has been working on and Titan refers to SCAR Titan.

Dgby714

2011-07-21 07:35:39

=)

This won't compile unless you move the internal functions out, but this is how I'd do it.

program new;
{$I SRL/SRL.scar}

type
TMonster = record
Names: TStringArray;
Color: TColor;
Hue, Sat, Tol: Extended;
end;
TMonsterArr = array of TMonster;

var
MonsterArr: TMonsterArr;

procedure LoadMonster(const Name: string);
function Monster(const Name: TStringArray; const Color: TColor; const Hue, Sat, Tol: Extended): TMonster;
begin
Result.Name := Name;
Result.Color := Color;
Result.Hue := Hue;
Result.Sat := Sat;
Result.Tol := Tol;
end;
begin
SetLength(MonsterArr, 0); //Reset

case (Name) of
'pig': begin
SetLength(MonsterArr, 2);
MonsterArr[0] := Monster([''], 0, 0.0, 0.0, 0.0);
MonsterArr[1] := Monster([''], 0, 0.0, 0.0, 0.0);
end;
'cow': begin
SetLength(MonsterArr, 2);
MonsterArr[0] := Monster([''], 0, 0.0, 0.0, 0.0);
MonsterArr[1] := Monster([''], 0, 0.0, 0.0, 0.0);
end;
'zombie': begin
SetLength(MonsterArr, 2);
MonsterArr[0] := Monster([''], 0, 0.0, 0.0, 0.0);
MonsterArr[1] := Monster([''], 0, 0.0, 0.0, 0.0);
end;
end;
end;

procedure FindMonster();
procedure _RandMArr(var Arr: TMonsterArr);
begin
//Didn't write this cause I'm lazy....
//Results the same arr >..>
end;
var
TempArr: TMonsterArr;
oC, A, H, J, I: Integer;
oH, oS: Extended;
Point: TPoint;
Points: TPointArray;
Points2D: T2DPointArray;
begin
if (not (LoggedIn)) then
Exit;

TempArr := MonsterArr;
_RandMArr(TempArr);

oC := GetToleranceSpeed();
GetToleranceSpeed2Modifiers(oH, oS);
try
SetColorToleranceSpeed(2);

H := High(TempArr);
for A := 0 to H do
with TempArr[A] do
begin
SetToleranceSpeed2Modifiers(Hue, Sat);

if (FindColorsSpiralTolerance(MSCX, MSCY, Points, Color, MSX1, MSY1, MSX2, MSY2, Tol)) then
if (Length(Points) > 1) then
begin
Points2D := TPAtoATPAEx(Points, 3, 3);
J := High(Points2D);

for I := 0 to J do
begin
Point := MiddleTPA(Points2D[I]);
MMouse(Point.X, Point.Y, RandomRange(-3, 3), RandomRange(-3, 3));

if (IsUpTextMultiCustom(Names)) then
begin
if (Random(5) <> 0) then
Continue;

WriteLn('Found Monster!');
GetMousePos(Point.X, Point.Y);
Mouse(Point.X, Point.Y, 0, 0, False);
if (not (ChooseOption('Attack'))) then
Mouse(Point.X, Point.Y, 0, 0, True);
Result := True;
Exit;
end;
end;
end;
end;
finally
SetColorToleranceSpeed(oC);
SetToleranceSpeed2Modifiers(oH, oS);
end;
end;

begin
end.