Results 1 to 12 of 12

Thread: Runtime errors bully? Try - Except is the answer for your problems.

  1. #1
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default Runtime errors bully? Try - Except is the answer for your problems.

    As the topic says.
    Ever seen when you come from school, wake up in teh morning and your scar says something about runtime error and does nothing?
    To avoid that, the creator of programming(who might that be?) has given us...

    Try Except

    There is 2 ways to get a script running good.
    a) script right
    b) script easy, right, and lazy.

    The how to do the a option would be longer explanation, so I will explain the b one, the meaning of this tutorial - Try Except.

    1. What is try except supposed to do?
    Avoid runtime errors!

    2. How to use it

    Well, I'll make an example instead of explanation.
    SCAR Code:
    program new;
    var
      A: array of Integer;
    begin
      SetArrayLength(A, 3); // from 0 to 2
      A[3] := 15; // We are trying to edit the "3" when "2" is the maximum
    end.
    That program would give a runtime error when ran.

    To avoid that we could use try except and do

    SCAR Code:
    program new;
    var
      A: array of Integer;
    begin
      SetArrayLength(A, 3); // from 0 to 2
      try
        A[3] := 15; // We are trying to edit the "3" when "2" is the maximum
      except
         Writeln('Oh noes! We tried to edit array slot which is out of range!');
      end;
    end.
    Basically what that script does, is sets array "A" length to 3 which means the thingys are 0, 1, 2 and we are trying to edit the 3 which doesnt exist.

    Try part of try catch, tries to execute the part of the program between try and catch, its a bit like begin and end.

    The part between except and end executes the part of the program which we have coded to do when our thing (in this case, the A[3] := 15) could not be executed.

    In this case, it would write "Oh noes! We tried to edit array slot which is out of range!" to the scar debug box.

    But, as many of you may think, if not, it ofcourse does not execute both the try and except part, because that'd be too leet.

    This is pretty simple thing so I think I dont need to explain more.

    Take the example code and play with it... (modify and learn)...

    Thx

  2. #2
    Join Date
    Jun 2007
    Location
    England
    Posts
    262
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Great tut.

  3. #3
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    Umm, ya, I have been fiddling with these things for a bit, and could you think of some other way to use this, like in a real rs script?

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  4. #4
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Is it okay if I pick a procedure from my unfinished draynor script?


    Well lets see, my uhber leet fishing procedure uses it
    SCAR Code:
    function Fish: Boolean;
    var
      FMark, F: Integer;
      A, Found, LoopRandomLO: Boolean;
    begin
      repeat
        if(FindSymbol(x, y, 'fish'))then
        begin
          Mouse(x, y, 3, 3, True);
          FFlag(0);
          repeat
            for F := 1 to 3 do
            begin
              case F of
                1: A := FindColorTolerance(x, y, Fc[F], MSX1, MSY1, MSX2, MSY2, 10);
                2: A := FindColorTolerance(x, y, Fc[F], MSX1, MSY1, MSX2, MSY2, 10);
                3: A := FindColorTolerance(x, y, Fc[F], MSX1, MSY1, MSX2, MSY2, 10);
              end;
              Wait(100 + Random(25));
            end;
            if (A) then
            begin
              MMouse(x, y, 2, 2);
              if (IsUpText('Net')) then
              begin
                Found := True;
                try
                  Fc[F] := GetColor(x, y);
                except
                  Writeln('Lol, runtime error would´ve come if we´d update color');
                  Writeln('Well, theres nothing wrong with our colors since we could');
                  Writeln('Find the fishing spot :)');
                end;
                Click(True);
                MarkTime(FMark);
              end;
            end;
            if(RandomLoggedOut)then
            begin
              Writeln('*Sigh* Logged out due to a random');
              NextPlayer(False);
              LoadISM;
              SendInterScarMessage(ISM[ISMno], 'Break');
              ISMno := ISMno + 1;
              LoopRandomLO := True;
            end;
            if(not(LoggedIn)) and (not(RandomLoggedOut)) then
            begin
              Writeln('We are logged out. Not due to a random.');
              Writeln('Player stays active, but nextplayer comes.');
              NextPlayer(False);
              LoadISM;
              SendInterScarMessage(ISM[ISMno], 'Break');
              ISMno := ISMno + 1;
            end;
          until (Found) or(LoopRandomLO) or (not(LoggedIn));
        end;
        while (TimeFromMark(FMark) < 20000) do
        begin
          try
            NontiBan;
            Wait(100 + Random(25));
            FasterRandoms;
            Wait(100 + Random(25));
            HandleWhirlPool;
            Wait(100 + Random(25));
            if(FindFight)then
            begin
              RunAwayDirection('w');
              Wait(8500 + Random(250));
              RunBack;
            end;
              if(not(FindDeformed(x, y, SmallNet, MIX1, MIY1, MIX2, MIY2)))
                or(FindNpcChatText('You need a net')) then
              begin
                FindNet(x, y);
                MMouse(x, y, 1, 1);
                if(IsUpText('Small'))then
                begin
                  Click(True);
                end else
                begin
                  MMouse(x, y, 0, 0);
                  if(IsUpText('Small'))then
                  begin
                    Click(True);
                  end else
                  begin
                    Writeln('Could not find your fishing equipment, changing player');
                    NextPlayer(False);
                    LoadISM;
                    SendInterScarMessage(ISM[ISMno], 'Break');
                    ISMno := ISMno + 1;
                  end;
                end;
              end;
              except
                Writeln('There was some crap in my Antiban and antirandoms');
                Writeln('Problem handled with Try - Except. ');
              end;
            end;
            GameTab(4);
            if(InvCount = 27) then
            begin
              Result := True;
            end;
          until(not(LoggedIn)) or (Result);
        end;

  5. #5
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    But, with the get color thing, I dont see how a runtime error would occur, unless you messed up and set the array length wrong.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  6. #6
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    No, its FC: array[1..3] of Integer
    but anyways, thats not the point, u know what I mean and how to use

    p.s: other than that its a pretty pwnz0r fishing proc

  7. #7
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    Ya, it is, but still, I guess I just know how to script "right" because I dont get runtime errors, and have never used Try or Except.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  8. #8
    Join Date
    Sep 2006
    Location
    New Jersey, USA
    Posts
    5,347
    Mentioned
    1 Post(s)
    Quoted
    3 Post(s)

    Default

    I'll try to fish out an example from one of my scripts.

    Some things just don't always work right, and it's quicker to use a try-except than to re-script the entire function to not give errors.
    Interested in C# and Electrical Engineering? This might interest you.

  9. #9
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    I'll try to fish out an example from one of my scripts.

    Some things just don't always work right, and it's quicker to use a try-except than to re-script the entire function to not give errors.
    I was just about to say that.

    One question: Does "you beat me in to it" mean that I was just about to say that or sumting like...

  10. #10
    Join Date
    Feb 2007
    Location
    Alberta, Canada
    Posts
    4,615
    Mentioned
    50 Post(s)
    Quoted
    429 Post(s)

    Default

    Ya, it does.

    Scripts: Edgeville Chop & Bank, GE Merchanting Aid
    Tutorials: How to Dominate the Grand Exchange

    Quote Originally Posted by YoHoJo View Post
    I like hentai.

  11. #11
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    k thx

  12. #12
    Join Date
    May 2006
    Location
    Qld, Australia
    Posts
    223
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    You could use this in DeclarePlayers so all the noobs dont compain for out of range errors =]
    Haven't scripted in a while, Willing to proofread, test and provide feedback.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. runtime errors plz help
    By phonokin in forum OSR Help
    Replies: 6
    Last Post: 04-02-2007, 04:22 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •