[Question]How to use "Try...Except"?

Discussion in 'Archives' started by Markizano, May 6, 2007.

[Question]How to use "Try...Except"?
  1. Unread #1 - May 6, 2007 at 3:15 PM
  2. Markizano
    Joined:
    Mar 2, 2006
    Posts:
    100
    Referrals:
    0
    Sythe Gold:
    0

    Markizano Active Member
    Banned

    [Question]How to use "Try...Except"?

    How do you use the "Try...Except" Procedure? In this function taken from the SRL includes. I found this code and wondered how the try and except thing is supposed to work.

    Code:
    function MMouse(dx, dy, RandX, RandY: Integer): Boolean;
    var
      Path: TPointArray;
      i, cx, cy, Lx, Ly, xx, yy, Dist, MidRX, MidRY: Integer;
      Step, SlowDown: Extended;
    begin
      Result := True;
      if (BenMouse) then
      begin
        try
          MidRX := Round(RandX / 2);
          MidRY := Round(RandY / 2);
          dx := dx + MidRX + NormDist(MidRX);
          dy := dy + MidRY + NormDist(MidRY);
          if dx < 0 then dx := 0;
          if dy < 0 then dy := 0;
          GetMousePos(cx, cy)
            if not ((Cx - dx = 0) and (Cy - dy = 0)) then
          begin
            Path := MakeMouseSplinePath(cx, cy, dx, dy, 7, 50, 40);
            Lx := cx;
            Ly := cy;
            for i := 0 to GetArrayLength(Path) - 1 do
            begin
              MoveMouse(Path[i].x, Path[i].y);
              Dist := Round(Sqrt((Path[i].x - dx) * (Path[i].x - dx) + (Path[i].y -
                dy) * (Path[i].y - dy)));
              if Dist < 50 then
              begin
                SlowDown := SlowDown + (0.05 * MouseSpeed);
              end;
              Wait(Round(((Random(2) + MouseSpeed) / 10) * Sqrt(Sqr(Path[i].x - Lx)
                + Sqr(Path[i].y - Ly)) + SlowDown));
              Lx := Path[i].x;
              Ly := Path[i].y;
            end;
          end;
          MoveMouseSmooth(dx, dy);
        except
          WriteLn('Error in BenMouse');
          WriteLn('Report: ' + IntToStr(cx) + ', ' + IntToStr(cy) + ' : ' +
            IntToStr(dx) + ', ' + IntToStr(dy) + ' : ' + IntToStr(mousespeed) +
              ';');
        end;
      end else
      begin // Start Mutant/RsN MMouse
        step := 4;
        xx := NormDist(RandX);
        yy := NormDist(RandY);
        dx := dx + xx;
        dy := dy + yy;
        GetMousePos(x, y);
        repeat
          if (Distance(x, y, dx, dy) < 100) then
            if (not (Distance(x, y, dx, dy) = 0)) then
              step := step - (10 / Distance(x, y, dx, dy));
          if (step < 1) then
            step := 1;
          x := x + Round((dx - x) / step);
          y := y + Round((dy - y) / step);
          MoveMouse(x, y);
          Wait(MouseSpeed);
        until (Distance(x, y, dx, dy) = 0);
      end;
    end;
    
    Somebody explain please...


    Markizano
     
  3. Unread #2 - May 6, 2007 at 5:01 PM
  4. Town
    Joined:
    Jan 21, 2007
    Posts:
    3,776
    Referrals:
    3
    Sythe Gold:
    5

    Town Grand Master
    Scar Programmers

    [Question]How to use "Try...Except"?

    It tries to do something, if it can't then it will do what except is.

    I use this in my flax picker:

    Code:
    try
        if (Players[CurrentPlayer].String2 = 'Both') then
          WriteLN('Picked And Spun: '+ IntToStr(StrToInt(Loads) * 28) + ' Flax');
        except
        end;
        try
        if (Players[CurrentPlayer].String2 = 'Flax') then
          WriteLN('Picked: '+ IntToStr(StrToInt(Loads) * 28) + ' Flax');
        except
        end;
        try
        if (Players[CurrentPlayer].String2 = 'Spin') then
          WriteLN('Spun: '+ IntToStr(StrToInt(Loads) * 28) + ' Flax');
        except
        end;
        try
        WriteLN('Grew: '+ IntToStr(i/2) +' Levels');
        except
        end;
        try
        if (Players[CurrentPlayer].String2 = 'Spin') then
          WriteLN('Gained: '+ IntToStr(StrToInt(Loads) * (28 * 15)) +' Crafting Experience');
        except
        end;
    I have to do Try Except because sometimes Loads = '' which is not a vaild integer. If that does happen, it will end.
     
  5. Unread #3 - May 6, 2007 at 6:24 PM
  6. WhoCares357
    Joined:
    Jan 21, 2007
    Posts:
    608
    Referrals:
    1
    Sythe Gold:
    0

    WhoCares357 Forum Addict

    [Question]How to use "Try...Except"?

    So, it's like a reverse if then? Never seen this before.
     
  7. Unread #4 - May 6, 2007 at 6:50 PM
  8. Starblaster100
    Joined:
    Apr 21, 2005
    Posts:
    335
    Referrals:
    2
    Sythe Gold:
    0

    Starblaster100 Forum Addict

    [Question]How to use "Try...Except"?

    Code:
    program New;
    
    Procedure ThisWillWork;
    Begin
      try
        Writeln('  Dividing 10 by 5, answer is:');
        Writeln('  '+IntToStr(10/5));
      except
        Writeln('  This is what will happen if the part in "try" couldnt work');
      finally
        Writeln('  This will happen whatever happens');
      end;
    end;
    
    Procedure ThisWontWork;
    Begin
      try
        Writeln('  Dividing 10 by 0, answer is:');
        Writeln('  '+IntToStr(10/StrToInt('0')));
      except
        Writeln('  This is what will happen if the part in "try" couldnt work');
      finally
        Writeln('  This will happen whatever happens');
      end;
    end;
    
    begin
      ClearDebug;
      Writeln('OK, here we go...');
      Wait(2000);
      ThisWillWork;
      Wait(3000);
      Writeln('');
      Writeln('And now...');
      Writeln('');
      Wait(2000);
      ThisWontWork;
    end.
    
    See if that helps.
     
  9. Unread #5 - May 7, 2007 at 9:35 AM
  10. Markizano
    Joined:
    Mar 2, 2006
    Posts:
    100
    Referrals:
    0
    Sythe Gold:
    0

    Markizano Active Member
    Banned

    [Question]How to use "Try...Except"?

    It does and I thank you. Now I am at my next question, how would I get something like this to work in VB6? I can tell from looking at it that it wouldn't be a sub/procedure, function, or property. It would have to be a whole new kind of way to program it. If...Then definitely has something to do with it, but exactly how I would go about doing that really boggles me. If nobody knows, then don't worry about it, just seeing if i could advance my knowledge of programming a bit.

    Off Topic: Who thinks that this was the first decent question about SCAR in a long time (Nothing stupid like "where's the dl link to scar" or "how do i install SRL" as I have consistently seen)?
     
  11. Unread #6 - May 7, 2007 at 10:01 AM
  12. Aphonix
    Joined:
    May 6, 2007
    Posts:
    209
    Referrals:
    0
    Sythe Gold:
    0

    Aphonix Active Member

    [Question]How to use "Try...Except"?

    Cool, looks interesting....
     
< 4917279560's questing,and MMing services!! | Remix's Membership trade-in! >

Users viewing this thread
1 guest


 
 
Adblock breaks this site