SRL Archive - OSR Help

Timer question


Bixby Sayz

2011-03-25 22:09:07

Reading the tutorial/examples on here they create a form and assign the form as the parent of the Timer.

What if you are not using forms? Do you have to create a dummy form just to use a timer?

Sex

2011-03-25 22:12:20

Use nil.

IPwnz

2011-03-25 22:13:17

Are you just trying to set up a timer in a script? This code does just that:
MarkTime(variablename);
Then to check how long it has been since you started the timer, just use:
TimeFromMark(variablename);

Bixby Sayz

2011-03-25 22:27:35

From: Sex
Use nil.


I tried that but it didn't work, leading me to wonder if it was my code or whether I couldn't use nil. Guess it was my code. Back to the drawing board!

From: IPwnz
Are you just trying to set up a timer in a script?


No I want a block of code to execute at specific time intervals independent of the main code execution. Which is got me interested in the TTimer.

footballjds

2011-03-25 22:35:21

From: Bixby Sayz
I tried that but it didn't work, leading me to wonder if it was my code or whether I couldn't use nil. Guess it was my code. Back to the drawing board!



No I want a block of code to execute at specific time intervals independent of the main code execution. Which is got me interested in the TTimer.


Like multi threading?

lordsaturn

2011-03-25 22:44:00

From: Bixby Sayz
No I want a block of code to execute at specific time intervals independent of the main code execution. Which is got me interested in the TTimer.
Sorry, you only get one thread.

Bixby Sayz

2011-03-25 22:45:17

From: footballjds
Like multi threading?


Yes, although I realize Simba does not support true multi-threading.

What got me interested in this: Digging around in the SRL includes I realized PlayerCurTime is never updated. Ever.

I could simply update it from time to time at various points in my code…Which got me to thinking: Why not use a TTimer and update it periodically automatically behind the scenes? Just starting to write a test script to see if it will actually do what I want.

footballjds

2011-03-25 22:53:44

PlayerCurTime never needs "updated" there is no such thing as a "timer" that "counts up"
The real thing that happens is you get the system time.
then when you wana know how much time has passed you get the system time again and subtract the previous time.

Bixby Sayz

2011-03-25 22:56:25

There were a couple other things I wanted to update at the same time. Seemed logical to group them all together.

Regardless having a devil of time coming up with a working test.

The example script in this tutorial does not work as documented. The output from the TTimer procs never display on screen.
http://villavu.com/forum/showthread.php?t=51578

footballjds

2011-03-25 23:45:46

The second example that he posted is the one you want to look at.
Run it in scar(NOT SIMBA). make sure you have report and the debug box visible.

Daniel

2011-03-26 02:19:41

[PHP]var
PlayerCurTime: Integer;
Timer: TTimer;

procedure OnTimer(Sender: TObject);
begin
PlayerCurTime := PlayerCurTime + 500;
end;

begin
Timer := TTimer.Create(nil);

Timer.Interval := 500;
Timer.OnTimer := @OnTimer;

repeat
Sleep(2000);
Writeln(IntToStr(PlayerCurTime));
Until(PlayerCurTime > 4000);
end.[/PHP]

Should work :) You get the gist of it though :)

Floor66

2011-03-26 09:44:37

From: Daniel
[PHP]var
PlayerCurTime: Integer;
Timer: TTimer;

procedure OnTimer(Sender: TObject);
begin
PlayerCurTime := PlayerCurTime + 500;
end;

begin
Timer := TTimer.Create(nil);

Timer.Interval := 500;
Timer.OnTimer := @OnTimer;

repeat
Sleep(2000);
Writeln(IntToStr(PlayerCurTime));
Until(PlayerCurTime > 4000);
end.[/PHP]

Should work :) You get the gist of it though :)


Didn't work for me; outputs "0" every time. I also made a thread about this a while back but I can't remember that anyone answered it :(

Bixby Sayz

2011-03-26 09:47:37

Added Timer.Enabled := True to your code to make it work but still got the following results:

Result in SCAR
Successfully compiled (140 ms)
0
0
0
0
0
Stopped execution (11500 ms)

Result in Simba

Compiled succesfully in 15 ms.
0
0
0
0
0
0
0
Successfully executed.

I think I will give up on this for the time being. It appears to be rather broken.