program TimeoutTutorial;
begin
Set Timeout is a quite fancy function. Some of you may know it from javascript. It adds some kind of a rudimentary Multithreading to scar, just like timers would do (Check out my Tutorial about Timer).
SCAR Code:
function SetTimeout(secs: Integer; procname: string): Integer;
For those of you who don't know what settimeout does, thats quite simple. SetTimeout Runs a given procedure or function after a certain time has passed.
Here's one example on how to use SetTimeout to write your progress Report after every second that your script is running.
SCAR Code:
program New;
var
loads:integer;
procedure proggy;
begin
ClearReport;
AddToReport('Loads Done:' + inttostr(loads));
AddToReport('Time Running:' + inttostr(GetTimeRunning));
// Woohow, a recursion ;]
SetTimeout(1000,'proggy');
end;
begin
//Initialize Proggy
proggy;
//MainLoop
repeat
wait(5000);
inc(loads);
until false;
end.
Functions to control SetTimeout
I scar there are two functions that you can use to control timeouts.
SCAR Code:
ClearTimeout(s:String);
//Cancels a single timed procedure set with SetTimeout.
SCAR Code:
procedure ClearTimeouts;
//Cancels all timed procedures set with SetTimeout.
(Quoted from freddies helpfile)
You can use these functions to break a timeout operation at any point after it has been initiated.
end.