SRL Archive - Research & Development Lounge

TimeOverIt function.


Raskolnikov

2007-11-16 21:28:10

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

2007-11-16 21:30:36

Basic, yet a good first procedure from you ;D

Raskolnikov

2007-11-17 11:44:37

Thanks =D. Anyone else try this?

Edit:
From: gerauchert
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

2007-11-17 12:26:55

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