Results 1 to 4 of 4

Thread: TimeOverIt function.

  1. #1
    Join Date
    Nov 2007
    Location
    Nowhereville
    Posts
    1,155
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default TimeOverIt function.

    This is supposed to be a failsafe that will exit if it finds the script is taking longer than expected, it will exit. I know it is basic but I made it as my first function anyways.
    Edit: Updated!!! Again!!!

    SCAR Code:
    program TimeOver;
    {.include SRL/SRL.scar}
    function TimeOverIt(ms: integer): boolean; //By cut em2 it
    begin
      if (TimeFromMark(Time) > ms) then
      begin
        Result := True;
        Writeln('The program will now terminate because it is taking too long.');
        Exit;
      end;
    end;

    procedure UseTimeOverIt;
    var Time: integer;
    begin
      MarkTime(Time);
      Wait(4000);
      TimeOverIt(3000);
    end;

    begin
      UseTimeOverIt;
    end.

    Thanks,
    Cut em2 it
    Formerly known as Cut em2 it

  2. #2
    Join Date
    Dec 2006
    Location
    Sweden
    Posts
    10,812
    Mentioned
    3 Post(s)
    Quoted
    16 Post(s)

    Default

    Basic, yet a good first procedure from you ;D


    Send SMS messages using Simba
    Please do not send me a PM asking for help; I will not be able to help you! Post in a relevant thread or make your own! And always remember to search first!

  3. #3
    Join Date
    Nov 2007
    Location
    Nowhereville
    Posts
    1,155
    Mentioned
    0 Post(s)
    Quoted
    3 Post(s)

    Default

    Thanks =D. Anyone else try this?

    Edit:
    Quote Originally Posted by gerauchert View Post
    looks ok, but why do you have it wait 5 seconds in the beginning...what if you wanted to have it terminate after 2 seconds or something?

    It also doesnt make too much sense to have the marktime in with the actual failsafe itself...it wont be too much of a failsafe if it is...

    i suggest something more on the lines of:

    SCAR Code:
    Program New;
    var Time: Integer;

    function TimeOverIt(ms: integer): boolean; //By cut em2 it
    begin
      if (TimeFromMark(Time) > ms) then
      begin
        Result := True;
        Writeln('The program will now terminate because it is taking too long.');
        Exit;
      end;
    end;

    begin
      SetupSRL;
      MarkTime(Time);
      repeat
        if(TimeOverIt(100000))then
        begin
           TerminateScript;
        end else
        DoSomething;
      until(SomeCondition);
    end.

    So this way the marktime is called and then the script can move on until it has reached the TimeOverIt...

    Hope that helps, and keep up the good work
    I understand that but I was trying to make an example. I guess i should've put it in a new procedure, I'll edit that.
    Formerly known as Cut em2 it

  4. #4
    Join Date
    Apr 2007
    Location
    Michigan -.-
    Posts
    1,357
    Mentioned
    2 Post(s)
    Quoted
    4 Post(s)

    Default

    looks ok, but why do you have it wait 5 seconds in the beginning...what if you wanted to have it terminate after 2 seconds or something?

    It also doesnt make too much sense to have the marktime in with the actual failsafe itself...it wont be too much of a failsafe if it is...

    i suggest something more on the lines of:

    SCAR Code:
    Program New;
    var Time: Integer;

    function TimeOverIt(ms: integer): boolean; //By cut em2 it
    begin
      if (TimeFromMark(Time) > ms) then
      begin
        Result := True;
        Writeln('The program will now terminate because it is taking too long.');
        Exit;
      end;
    end;

    begin
      SetupSRL;
      MarkTime(Time);
      repeat
        if(TimeOverIt(100000))then
        begin
           TerminateScript;
        end else
        DoSomething;
      until(SomeCondition);
    end.

    So this way the marktime is called and then the script can move on until it has reached the TimeOverIt...

    Hope that helps, and keep up the good work
    METAL HEAD FOR LIFE!!!

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Need help with a function.
    By Floor66 in forum OSR Help
    Replies: 15
    Last Post: 04-15-2008, 02:03 PM
  2. Replies: 2
    Last Post: 02-27-2008, 05:20 PM
  3. Replies: 2
    Last Post: 02-26-2008, 08:26 PM
  4. [FUNCTION] FindDoorColour: integer; By ZephyrsFury [FUNCTION]
    By ZephyrsFury in forum Research & Development Lounge
    Replies: 10
    Last Post: 07-27-2007, 08:45 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
  •