SRL Archive - RS3 Help

TTimeMarker question


HKbotz

2014-12-31 06:23:43

So I was writing a script that uses TTimeMarker and noticed that it was failing because it thought it waited for a certain amount of time, but really it had been like 2 seconds, I think I had it set to wait for 10. Anyway it was clearly not waiting even close to long enough.

Looking closer I realized when I called timer.getTime() it was spitting out some really big number, I am just curious as to why this is happening and how to get around it.
I tried adding timer.reset() before calling timer.getTime() but it didn't make any difference, I still get a really big number.

Does the timer have to be started before .getTime() works properly or is there something else I'm missing?

Any help is appreciated :)

Ex.
program new;
{$i srl-6/srl.simba}

var
timer: TTimeMarker;

begin
timer.reset();
writeln('timer.getTime(): ' + intToStr(timer.getTime()));
end.

Output:
timer.getTime(): 282755836
Successfully executed.

Smidqe

2014-12-31 06:36:34

Yes, you have to use timer.start() to start the timer.

program new;
{$i srl-6/srl.simba}

var
timer: TTimeMarker;

begin
timer.start();
writeln('timer.getTime(): ' + intToStr(timer.getTime()));
end.

Explanation:

Reason why it gives such a huge number is because it hasn't initialised the __prevMark to the current time.

These functions are found in time.simba, as you can see if the __prevMark is not initialised by TTimeMarker.start() it would be 0, and the time would be equal to getTickCount64(), which is the system's time and therefore a very large number.
function TTimeMarker.getTime(): LongWord;
begin
if not Self.paused then
Result := Self.time + (getTickCount64() - Self.__prevMark)
else
Result := Self.time;
end;

Once you use the timer.start(), it will set __prevMark to the time it was started.
procedure TTimeMarker.start();
begin
Self.__prevMark := getTickCount64(); // used for adding time after a pause

// if it hasn't been started yet
if (not Self.paused) then
begin
Self.startTime := getTickCount64();
Self.time := 0;
end;

Self.paused := False;
end;

HKbotz

2014-12-31 06:47:38

From: Smidqe
Yes, you have to use timer.start() to start the timer.

program new;
{$i srl-6/srl.simba}

var
timer: TTimeMarker;

begin
timer.start();
writeln('timer.getTime(): ' + intToStr(timer.getTime()));
end.

Explanation:

Reason why it gives such a huge number is because it hasn't initialised the __prevMark to the current time.

These functions are found in time.simba, as you can see if the __prevMark is not initialised by TTimeMarker.start() it would be 0, and the time would be equal to getTickCount64(), which is the system's time and therefore a very large number.
function TTimeMarker.getTime(): LongWord;
begin
if not Self.paused then
Result := Self.time + (getTickCount64() - Self.__prevMark)
else
Result := Self.time;
end;

Once you use the timer.start(), it will set __prevMark to the time it was started.
procedure TTimeMarker.start();
begin
Self.__prevMark := getTickCount64(); // used for adding time after a pause

// if it hasn't been started yet
if (not Self.paused) then
begin
Self.startTime := getTickCount64();
Self.time := 0;
end;

Self.paused := False;
end;


Ah, that makes sense. Thanks for the explanation :)