PDA

View Full Version : TimeOverIt function.



Raskolnikov
11-17-2007, 02:28 AM
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!!!

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

Harry
11-17-2007, 02:30 AM
Basic, yet a good first procedure from you ;D

Raskolnikov
11-17-2007, 04:44 PM
Thanks =D. Anyone else try this?

Edit:

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:


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.

gerauchert
11-17-2007, 05:26 PM
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:


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 ;)