Results 1 to 13 of 13

Thread: Timer question

  1. #1
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default Timer question

    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?
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  2. #2
    Join Date
    Oct 2009
    Location
    Stockton, CA
    Posts
    2,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Use nil.
    Join the IRC! irc.rizon.net:6667/srl | SQLite (0.99rc3+) | SRL Doc | Simba Doc | Extra Simba Libraries (openSSL & sqlite3)
    Quote Originally Posted by #srl
    10:45 < Toter> daphil when can get sex anyday I want
    10:45 < Toter> he is always on #SRL
    "A programmer is just a tool which converts caffeine into code"

  3. #3
    Join Date
    Nov 2007
    Posts
    326
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

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

    Check out my Edgeville Smelter!

  4. #4
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by Sex View Post
    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!

    Quote Originally Posted by IPwnz View Post
    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.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  5. #5
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    Quote Originally Posted by Bixby Sayz View Post
    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?

  6. #6
    Join Date
    Mar 2007
    Posts
    1,700
    Mentioned
    0 Post(s)
    Quoted
    8 Post(s)

    Default

    Quote Originally Posted by Bixby Sayz View Post
    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.

  7. #7
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    Quote Originally Posted by footballjds View Post
    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.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  8. #8
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    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.

  9. #9
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

    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
    Last edited by Bixby Sayz; 03-26-2011 at 03:09 AM.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

  10. #10
    Join Date
    Feb 2007
    Location
    PA, USA
    Posts
    5,240
    Mentioned
    36 Post(s)
    Quoted
    496 Post(s)

    Default

    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.

  11. #11
    Join Date
    Dec 2006
    Location
    Sydney, New South Wales, Australia
    Posts
    4,603
    Mentioned
    15 Post(s)
    Quoted
    42 Post(s)

    Default

    PHP Code:
    var
      
    PlayerCurTimeInteger;
      
    TimerTTimer;

    procedure OnTimer(SenderTObject);
    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
    Should work You get the gist of it though
    You may contact me with any concerns you have.
    Are you a victim of harassment? Please notify me or any other staff member.

    | SRL Community Rules | SRL Live Help & Chat | Setting up Simba | F.A.Q's |

  12. #12
    Join Date
    Feb 2007
    Location
    Access Violation at 0x00000000
    Posts
    2,865
    Mentioned
    3 Post(s)
    Quoted
    18 Post(s)

    Default

    Quote Originally Posted by Daniel View Post
    PHP Code:
    var
      
    PlayerCurTimeInteger;
      
    TimerTTimer;

    procedure OnTimer(SenderTObject);
    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
    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
    Ce ne sont que des gueux


  13. #13
    Join Date
    Aug 2009
    Location
    Nova Scotia, Canada
    Posts
    604
    Mentioned
    0 Post(s)
    Quoted
    56 Post(s)

    Default

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

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

    Result in Simba
    Simba Code:
    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.
    Never ever approach a computer saying or even thinking "I will just do this quickly".

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •