Results 1 to 7 of 7

Thread: Need help with Exception: Access violation

  1. #1
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default Need help with Exception: Access violation

    I'm just trying to make a double check function that if found on 2nd check will output 'true'. I keep getting an error - "Exception: Access violation" - when I change the variable c to 2, imitating the objective wasn't met. Can't figure out why. Please someone fill me in. This should return true if c is one or false if c is two.

    Simba Code:
    program new;

    var
      c: integer;


    function DoubleCheckFunction: Boolean;
    begin
      result := false;
      if (c = 1) then //objective met would go here
        result := true
      else
      begin  //If I change c to 2 = error
        c := 1; //Changing this signifies whether the objective was met or not
        if DoubleCheckFunction then
          result := true;
      end;
    end;


    begin
     c := 0;
     if DoubleCheckFunction then
       writeln('true')
     else writeln('false');

    end.
    Last edited by bud_wis_er_420; 02-19-2013 at 01:53 AM.
    Not scripting for RS anymore, sorry. Banned too many times.
    MY SCRIPTS

  2. #2
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Do you mean something like this? Where you can have multiple else if's? (usually good to have a default else, to make sure what ever you are evaluating gets evaluated - isn't always done, but is good practice)

    Simba Code:
    var
      c: integer;

    function DoubleCheckFunction: Boolean;
    begin
      result := false;
      if (c = 1) then //objective met would go here
        result := true
      else if (c = 2) then
      begin  //If I change c to 2 = error
        c := 1; //objective met would go here
        if DoubleCheckFunction then
          result := true;
      end else
        Writeln('c is not equal to 1 or 2, but is = ' + IntToStr(c));
    end;

    begin
     c := 0;
     if DoubleCheckFunction then
       writeln('true')
     else
       writeln('false');
    end.

  3. #3
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default

    No, maybe this will explain better. Sry I'm sometimes terrible at explaining things from my point of view.

    Simba Code:
    function DoubleCheckFunction: Boolean;
    begin
      result := false;

      //Code: Do something here

      // If Do Something/c = This happend/1
      if (c = 1) then //objective met would go here
        result := true
      else
      begin
        //Do something failed

        //Code: Now Do this: fail safe

        //Below now checks one more time if objective is
             //complete w/o having to reenter all the above code

        //If I hange c to 2 = error
        c := 1; //objective met would go here
        if DoubleCheckFunction then
          result := true;
      end;
    end;

    here is my actual funtion I'm working on. I made the above function to test that it will output true if the objective wan't met the first time.
    FindUrnInInv returns true if 2 are found in inv. So to save coding lines, this should repeat it's self until 2 urns are found in inv. I want it set up this way is because I'm using the same func on other areas.

    Simba Code:
    //this function is just added so you can understand the bottom func
    function FindUrnInInv(move: Boolean): Boolean;
    var
      ItemSlot: integer;
    begin
      if CheckLogin then Exit;
      result := false;

      color := GetACAUrnColor;
      count := CountItems('color', color, []);
      if (count = 2) then
      begin
        WriteDebug('Urns found, Checking if in correct spot');
        MoveUrns;
        result := true;
      end else
      begin
        WriteDebug('At least 2 Urns not found');
        Exit;
      end;
      box := InvBox(1);
      if not FindColor(x,y,color,box.x1,box.y1,box.x2,box.y2) then
      begin
        WriteDebug('Didn''t find urn in inv slot one');
        result := true;
      end;
    end;  

    // This function shoule repeat twice if inv is empty, once if already have one urn in inv.
    function GetBankUrns: Boolean;
    var
      BankSlot: integer;
      Pt: TPoint;
    begin
      if CheckLogin then Exit;
      result := false;
      WriteDebug('Searching for urn in bank');
      SearchBank(UrnType);
      MouseBankSlot(1, 3);
      if WaitFunc(@IsUrnUpText,RandomRange(200,220), RandomRange(900,1000)) then
      Begin
        ClickMouse2(0);
        if WaitOptionMulti('thdraw-2', 1000) then
        begin
          if FindUrnInInv then
            result := true;
          else GetBankUrns;
        end else
        begin
          WriteDebug('Did not find option to withdraw 2');
        end;
      end;
    end;


    This:
    Simba Code:
    function GetBankUrns: Boolean;
    var
      BankSlot: integer;
      Pt: TPoint;
    begin
      if CheckLogin then Exit;
      result := false;
      WriteDebug('Searching for urn in bank');
      SearchBank(UrnType);
      MouseBankSlot(1, 3);
      if WaitFunc(@IsUrnUpText,RandomRange(200,220), RandomRange(900,1000)) then
      Begin
        ClickMouse2(0);
        if WaitOptionMulti('thdraw-2', 1000) then
        begin
          if FindUrnInInv then
            result := true;
          else GetBankUrns;
        end else
        begin
          WriteDebug('Did not find option to withdraw 2');
        end;
      end;
    end;

    Instead of this:

    Simba Code:
    function GetBankUrns: Boolean;
    var
      BankSlot: integer;
      Pt: TPoint;
    begin
      if CheckLogin then Exit;
      result := false;
      WriteDebug('Searching for pouch in bank');
      SearchBank(UrnType);
      MouseBankSlot(1, 3);
      if WaitFunc(@IsUrnUpText,RandomRange(200,220), RandomRange(900,1000)) then
      Begin
        ClickMouse2(0);
        if WaitOptionMulti('thdraw-2', 1000) then
        begin
          if FindUrnInInv then
            result := true;
          else
          begin
            WriteDebug('Searching for pouch in bank');
            SearchBank(UrnType);
            MouseBankSlot(1, 3);
            if WaitFunc(@IsUrnUpText,RandomRange(200,220), RandomRange(900,1000)) then
            Begin
              ClickMouse2(0);
              if WaitOptionMulti('thdraw-2', 1000) then
              begin
                if FindUrnInInv then
                  result := true;
              end;
            end;
          end
        end else
        begin
          WriteDebug('Did not find option to withdraw 2');
        end;
      end;
    end;
    Last edited by bud_wis_er_420; 02-19-2013 at 01:40 AM.
    Not scripting for RS anymore, sorry. Banned too many times.
    MY SCRIPTS

  4. #4
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    I wouldn't recommend recursively calling your methods for a small context function as illustrated by your snippets. Especially since you have no base case for the recursive calls, so it's likely that you'll end up in an infinite loop.

    if you need to wait for a urn or check for a urn, etc. while (condition(s)) do can create a more safe fail checking system. Saving coding lines isn't always grand, especially since recursive methods will take more time to execute.

  5. #5
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default

    The funcs are not finished. I know, about the inf loop and will have fail safes in there to kick it out. I'm just trying to get why I'm getting the error . I have repeated code, in my script over and over again. I'm trying ideas on how to save lines of code without have to make numerous small snip-it functions to recall things again.

    The best explanation I could think of was this tiny function below. It should return true if c = 1 and if you manually change c to 2 or anything else but 1, this would simulate the script doing it in run time giving an out put of false.

    This is saying:

    Do This

    If it happend then
    func = true - end of func
    If not happen then
    DO This
    If not do this then Exit - end func
    else continue

    restart func

    Do This

    If it happend then
    func = true - end of func

    Simba Code:
    function DoubleCheckFunction: Boolean;
    begin
      result := false;

      //Code goes here: Do something here  = 10 lines of code

      // If Do Something/c = This happend/1
      if (c = 1) then //objective met would go here
        result := true
      else
      begin
        //Do something failed

        //Code goes here: Now Do this to correct things

        //Below now checks one more time if we can complete objective
        //  w/o having to reenter all the above code

        //1 = objective met(func will = true)
        //2 = objective not met(func will = false)
        c := 1; //If I change c to 2 I get the error
        // saves me from haveing to repeat  'Do something here'  = 10 lines of code
        if DoubleCheckFunction then
          result := true;

        //if above is false end func
      end;
    end;
    Last edited by bud_wis_er_420; 02-19-2013 at 02:32 AM.
    Not scripting for RS anymore, sorry. Banned too many times.
    MY SCRIPTS

  6. #6
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    Quote Originally Posted by bud_wis_er_420 View Post
    The funcs are not finished. I know, about the inf loop and will have fail safes in there to kick it out. I'm just trying to get why I'm getting the error . I have repeated code, in my script over and over again. I'm trying ideas on how to save lines of code without have to make numerous small snip-it functions to recall things again.

    The best explanation I could think of was this tiny function below. It should return true if c = 1 and if you manually change c to 2 or anything else but 1, this would simulate the script doing it in run time giving an out put of false.

    Simba Code:
    program new;

    var
      c: integer;


    function DoubleCheckFunction: Boolean;
    begin
      result := false;
      if (c = 1) then //objective met would go here
        result := true
      else
      begin  //If I change c to 2 = error
        c := 1; //Changing this signifies whether the objective was met or not
        if DoubleCheckFunction then
          result := true;
      end;
    end;


    begin
     c := 0;
     if DoubleCheckFunction then
       writeln('true')
     else writeln('false');

    end.
    The example above, is not an effective recursive function. You would need a variable to check/use as a base case for the function to stop. As stands, the example will only continue to loop on end; think about expanding the function to something you know how to use before trying to simplify code to a recursive function (even though it's not always the best choice, aside from potential cleaner code)
    Edit: I see your pseudo code now, and if you repeat a piece of code, you could make it into a small function, and call it in later functions that make use of it.
    Last edited by Le Jingle; 02-19-2013 at 02:30 AM.

  7. #7
    Join Date
    Mar 2007
    Location
    Mars, I thought all men were from Mars.
    Posts
    513
    Mentioned
    7 Post(s)
    Quoted
    124 Post(s)

    Default

    ohhhh I see what your saying, it IS in an inf loop, lol. I get it now. Fixed

    Simba Code:
    function DoubleCheckFunction: Boolean;
    begin
      result := false;
      if (c = 1) then
        result := true
      else
      begin
        c := 2;
        if (c = 1) then // <<<--  failsafe, lol
          if DoubleCheckFunction then
            result := true;
      end;
    end;

    I'd +1 rep but your to only one that seems to help me and can't give you anymore lol

    although I did already have it right. Just messed up my example, lol

    Simba Code:
    function GetBankUrns: Boolean;
    var
      BankSlot: integer;
      Pt: TPoint;
    begin
      if CheckLogin then Exit;
      result := false;
      WriteDebug('Searching for urn in bank');
      SearchBank(UrnType);
      MouseBankSlot(1, 3);
      if WaitFunc(@IsUrnUpText,RandomRange(200,220), RandomRange(900,1000)) then
      Begin
        ClickMouse2(0);
        if WaitOptionMulti('thdraw-2', 1000) then
        begin
          if FindUrnInInv then // <<<--- FailSafe
            result := true;
          else GetBankUrns; /// <<<--- Repeat Func
        end else
        begin
          WriteDebug('Did not find option to withdraw 2');
        end;
      end;
    end;
    Last edited by bud_wis_er_420; 02-19-2013 at 02:50 AM.
    Not scripting for RS anymore, sorry. Banned too many times.
    MY SCRIPTS

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
  •