SRL Archive - OSR Help

Exception in Script: Access violation


Emaziz

2010-07-28 07:48:44

So.. I'm working on a pickpocker using reflection. I really have no clue what's causing the error 'Exception in Script: Access violation'

I have all the newest updates, and I'm using Simba.
Thanks in advance!

Error occurs when compiling

{.include SRL\SRL\misc\SMART.SCAR}
{.include SRL\SRL.scar}
{.include reflection\reflection.simba}
{ Valid locations is: 'VPG' Varrock Palace Guards, 'DMF' Draynor Master Farmer
{
{}
var
Level, XP: integer;
NPCTarget: TNPC;
FoodName: string;
TargetHitDamage: integer;
GoldStolen, PrevGold, StartGold: integer;


const
World = 108;
Signed = True;
Members = False; // Duh!

procedure DeclarePlayers;
begin
HowManyPlayers := 1;
NumberOfPlayers(HowManyPlayers);
CurrentPlayer := 0;
with Players[0] do
begin
Name :='';
Pass :='';
Nick :='oli';
Level[SKILL_HITPOINTS] := 10; // Your hitpoints level (Not lifepoints!)
Active := True;
Booleans[0] := True; // If wanted EXP is relative to your current EXP.
Integers[0] := 0; // Wanted EXP, 0 is continue 'til stopped.
Integers[1] := 70; // Amount of lifepoints your food heals
Booleans[1] := True; // Wanna take breaks?
Integers[2] := 50; // How many minutes between each break. +- 5 minutes.
Integers[3] := 10; // How many minutes to break for. +- 5 minutes.
Loc := 'VPG'; // Location as to where to pickpock;
end;

{

}
end;

// DO NOT CHANGE THE FOLLOWING CONST ITEMS \\
const
XP_Man = 8;
XP_Farmer = 14.5;
XP_Warrior = 26;
XP_Guard = 46.8;
XP_MasterFarmer = 43;
DMG_Man = 10;
DMG_Farmer = 0;
DMG_Warrior = 0;
DMG_Guard = 30;
DMG_MasterFarmer = 30;

//\\\\\\\\\\\\\\\\\\\////////////////////\\

function LoadPath(Path:String;Bank:Boolean): TTileArray;
begin
if (not Bank) then
begin
case Path of
'DMF':
begin
SetLength(Result, 2);
Result[0] := Point(3856, 2606);
Result[1] := Point(3842, 2614);
end;
'VPG':
begin
SetLength(Result, 8);
Result := [
Tile(3167, 3489), Tile(3177, 3489), Tile(3185, 3489),
Tile(3195, 3487), Tile(3196, 3480), Tile(3197, 3471),
Tile(3200, 3459), Tile(3212, 3462)];
end;
end;
end;
if (Bank) then
begin
case Path of
'DMF':
begin
SetLength(Result, 2);
Result[0] := Point(3842, 2614);
Result[1] := Point(3855, 2606);
end;
'VPG':
begin
SetLength(Result, 9);
Result := [
Tile(3212, 3463), Tile(3212, 3457), Tile(3202, 3457),
Tile(3197, 3465), Tile(3195, 3474), Tile(3191, 3482),
Tile(3188, 3487), Tile(3179, 3487), Tile(3172, 3488)];
end;
end;
end;
writeln('Loaded path');
end;

procedure Terminate;
begin
writeln('Terminating script...');
TerminateScript;
end;

procedure Walk(Bank : boolean);
begin
R_MakeCompass('N');
case Bank of
True: // To bank
WalkPath(LoadPath(Players[CurrentPlayer].Loc,True));
False: // To target
begin
WalkPath(LoadPath(Players[CurrentPlayer].Loc,False));
end;
end;
writeln('Done walking');
end;

function IsFood(Item: TInvItem):boolean;
begin
if (Item.Actions[0] = 'Eat') then
Result := True;
if (Item.Actions[0] <> 'Eat') then
Result := False;
end;

function GetTargetHitDMG: integer;
begin
Result := -1;
case NPCTarget.Name of
'Guard': Result := DMG_Guard;
'Master Farmer': Result := DMG_MasterFarmer;
end;
if Result = -1 then
writeln('Returned -1 as HitDMG, why???');
end;

function GetTargetXP: Extended;
begin
Result := -1;
case NPCTarget.Name of
'Guard': Result := XP_Guard;
'Master Farmer': Result := XP_MasterFarmer;
end;
if Result = -1 then
writeln('Returned -1 as XP...');
end;

function PickFailed: boolean;
begin
Result := True;
if (PrevGold <> GoldStolen) then
begin
Result := False;
PrevGold := GoldStolen;
end;

end;

procedure Eat;
var
i: integer;
begin
for i := 1 to 28 do
begin
if (IsFood(GetInvItemAt(i))) then
begin
R_ClickItem(i,True,'');
while (GetInvItemAt(i).StackSize <> -1) do
begin
wait(50);
end;
end;
end;
end;

procedure CheckEat;
begin
if R_GetMMLevels('hp') <= TargetHitDamage then
begin
Eat;
while (R_GetMMLevels('hp') + Players[CurrentPlayer].Integers[1]) <= (Players[CurrentPlayer].Level[SKILL_HITPOINTS]*10) do
begin
Eat;
end;
end;
end;

function GetGold: integer;
var
G: TInvItem;
begin
Result := 0;
if R_ItemNameExists(G,'Coins') then
begin
Result := G.StackSize;
end;
end;

function GetTarget: boolean;
begin
Result := False;
case Players[CurrentPlayer].Loc of
'VPG':
Result := FindNPC('uard',NPCTarget);
'DMF':
Result := FindNPC('aster Farm',NPCTarget);
end;
if (Result = False) then
GetTarget;
if (Result = False) then
begin
writeln('Couldnt find NPC.');
Terminate;
end;
end;

function IsCloseToTarget: boolean;
begin
Result := False;
if DistanceFrom(NPCTarget.Tile) <= 10 then
begin
Result := True;
end;
end;

function PickTarget: boolean;
var TP: TPoint;
begin
PrevGold := GoldStolen;
TP := TileToMs(NPCTarget.Tile, NPCTarget.Height);
MMouse(TP.x,TP.y,0,0);
if IsUptext('ickpock') then
begin
ClickMouse(Tp.x,tp.y,True);
end;
if not R_IsUpText('ickpock') then
begin
ClickMouse(Tp.x,tp.y,false);
wait(200);
if not R_ChooseOption('ickpock') then
begin
writeln('Failed to find pickpock option.');
Terminate;
end;
end;
wait(1000);
end;

procedure BankOpen;
begin
case Players[CurrentPlayer].Loc of
'VPG': OpenBankNPC;
'DMF': OpenBank('dr',true,true);
end;
end;

procedure DepositStuff;
begin
if (R_BankScreen) then
R_DepositAllButIDEx([617,995]);
end;

procedure PrintStats;
begin
end;

procedure MainLoop;
begin
while (true) do
begin
BankOpen;// Opens bank
DepositStuff; // Deposits anything but coins.
WithdrawFood; // Withdraws item from slot 1
CloseBank; // Closes bank
Walk(False); // Walks to pickpocking place
while (HasFood) do
begin
CheckEat; // Checks if LP is too low to risk a fail, eats if it is
GetTarget; // Looks for the target
PickTarget; // Pickpockets the target
GoldStolen := GetGold - StartGold; // Updates gold stats
end;
Walk(True); // Walks to bank
PrintStats; // Prints stats
end;
end;


begin
Smart_Server := World;
Smart_Members := Members;
Smart_Signed := Signed;
DeclarePlayers;
SetupSRL;
SetupReflectionEx(False);
LogInPlayer;
SetAngle(True);
MainLoop;
StartGold := GetGold;
GoldStolen := GetGold - StartGold;
PrevGold := GoldStolen;
end.

Shuttleu

2010-07-28 07:51:24

when does it happen and does it always happen at the same place?

~shut

Emaziz

2010-07-28 08:03:02

It happens at compile time.

EvilChicken!

2010-07-28 08:24:41

What line does it occur on?

It's a bit difficult reading your script. If you were to exercise correct standards, you'd be amazed how much easier it gets on the eyes and generally how much easier it gets to debug scripts. There are plenty of tutorials on the subject over at Tutorial Island. :)

Emaziz

2010-07-28 08:39:19

It doesn't say anything about the line.. Only output is 'Exception in Script: Access violation', that's what makes it so hard.. :P
Sorry about the script looks, I'm used to automatic tab spaces and stuff from Visual Studio ^^,

I reformatted the code, I haven't read about the SCAR/Simba standards, but it should look cleaner now.. I'll learn specific standards later ^^,

Dan Cardin

2010-07-28 09:38:03

trying putting you main loop where Loop is.
  try
Loop
except
Writeln(ExceptionToString(ExceptionType, ExceptionParam));
end;
i think that might work.

Emaziz

2010-07-28 10:02:13

From: Dan Cardin
trying putting you main loop where Loop is.
  try
Loop
except
Writeln(ExceptionToString(ExceptionType, ExceptionParam));
end;
i think that might work.


The error occurs when compiling, not running :\
Thanks tho'

EDIT::

I managed to locate the problem to the Eat procedure by commenting out stuff, also the specific line causing the problem is
while (GetInvItemAt(i).StackSize <> -1) do
, and the very problem is GetInvItemAt(i). Yet that function works in
if (IsFood(GetInvItemAt(i))) then
Any idea why so?


procedure Eat;
var
i: integer;
begin
for i := 1 to 28 do
begin
if (IsFood(GetInvItemAt(i))) then
begin
R_ClickItem(i,True,'');
while (GetInvItemAt(i).StackSize <> -1) do
begin
wait(50);
end;
end;
end;
end

The function is simply to check whether food is eaten or not, I can simply add a wait(1000) instead, and I will for now. I still think the error is weird?

Wizzup?

2010-08-01 19:36:47

Can you file as bug for this? There should be no errors on compile time.