Results 1 to 8 of 8

Thread: Exception in Script: Access violation

  1. #1
    Join Date
    Mar 2009
    Location
    Norway
    Posts
    493
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default Exception in Script: Access violation

    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

    SCAR Code:
    {.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.
    Last edited by Emaziz; 07-28-2010 at 12:48 PM.

  2. #2
    Join Date
    Aug 2007
    Location
    in a random little world
    Posts
    5,778
    Mentioned
    0 Post(s)
    Quoted
    7 Post(s)

  3. #3
    Join Date
    Mar 2009
    Location
    Norway
    Posts
    493
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    It happens at compile time.

  4. #4
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    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.

  5. #5
    Join Date
    Mar 2009
    Location
    Norway
    Posts
    493
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    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 ^^,
    Last edited by Emaziz; 07-28-2010 at 12:49 PM.

  6. #6
    Join Date
    Apr 2007
    Posts
    3,152
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    trying putting you main loop where Loop is.
    SCAR Code:
    try
        Loop
      except
        Writeln(ExceptionToString(ExceptionType, ExceptionParam));
      end;
    i think that might work.
    SCAR Tutorials: The Form Tutorial | Types, Arrays, and Classes
    Programming Projects: NotePad | Tetris | Chess


  7. #7
    Join Date
    Mar 2009
    Location
    Norway
    Posts
    493
    Mentioned
    0 Post(s)
    Quoted
    4 Post(s)

    Default

    Quote Originally Posted by Dan Cardin View Post
    trying putting you main loop where Loop is.
    SCAR Code:
    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
    SCAR Code:
    while (GetInvItemAt(i).StackSize <> -1) do
    , and the very problem is GetInvItemAt(i). Yet that function works in
    SCAR Code:
    if (IsFood(GetInvItemAt(i))) then
    Any idea why so?

    SCAR Code:
    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?
    Last edited by Emaziz; 07-28-2010 at 02:21 PM.

  8. #8
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    13,692
    Mentioned
    146 Post(s)
    Quoted
    130 Post(s)

    Default

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



    The best way to contact me is by email, which you can find on my website: http://wizzup.org
    I also get email notifications of private messages, though.

    Simba (on Twitter | Group on Villavu | Website | Stable/Unstable releases
    Documentation | Source | Simba Bug Tracker on Github and Villavu )


    My (Blog | Website)

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
  •