Results 1 to 16 of 16

Thread: timer

  1. #1
    Join Date
    Sep 2006
    Posts
    322
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default timer

    How can I make an infinite loop, that repeats every 30 seconds?
    "SRL is the best SCAR community in the World, with the most talented programmers: adjust your volume."
    -Wizzup?

  2. #2
    Join Date
    Sep 2008
    Location
    Not here.
    Posts
    5,422
    Mentioned
    13 Post(s)
    Quoted
    242 Post(s)

    Default

    SCAR Code:
    repeat
      dostuff;
      wait(30000);
    until(false);//never ending

  3. #3
    Join Date
    Sep 2006
    Posts
    322
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    thanks
    "SRL is the best SCAR community in the World, with the most talented programmers: adjust your volume."
    -Wizzup?

  4. #4
    Join Date
    Oct 2009
    Location
    Melb, Australia
    Posts
    179
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  5. #5
    Join Date
    Aug 2009
    Posts
    242
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by code841 View Post
    That's assuming the "dostuff" will take less than 1 millisecond.
    ??? Whats that meant to mean
    it will

    do stuff
    wait 3 secs
    Repeat
    I see Now, says the blind man

  6. #6
    Join Date
    Oct 2006
    Posts
    500
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    That would mean if the procedure DoStuff; had Wait(20000); it wouldn't repeat every 30 seconds would it. It would wait for 20 seconds, then wait for 30 seconds, totaling 50 seconds, then repeating.

  7. #7
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    well technically he never said he wanted it to do stuff, he just said an infinite loop that repeats every 30 secs, so it'd be:

    SCAR Code:
    repeat
      wait(30*60000);
    until(2+2=5);

    that might only loop once, not sure

  8. #8
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by Baked0420 View Post
    well technically he never said he wanted it to do stuff, he just said an infinite loop that repeats every 30 secs, so it'd be:

    SCAR Code:
    repeat
      wait(30*60000);
    until(2+2=5);

    that might only loop once, not sure
    your math is wrong its wait(30*1000);

    since 1000 = 1 sec,

    also, the loop will never end, because obviously 2+2=22
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  9. #9
    Join Date
    Jan 2008
    Location
    Houston, Texas, USA
    Posts
    770
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Awkwardsaw View Post
    your math is wrong its wait(30*1000);

    since 1000 = 1 sec,

    also, the loop will never end, because obviously 2+2=22
    Haha 2+2= 22 made me lol

  10. #10
    Join Date
    Feb 2006
    Location
    Tracy/Davis, California
    Posts
    12,631
    Mentioned
    135 Post(s)
    Quoted
    418 Post(s)

    Default

    Wow, ROFL thread, he got the point...

  11. #11
    Join Date
    Jan 2008
    Location
    Houston, Texas, USA
    Posts
    770
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by YoHoJo View Post
    Wow, ROFL thread, he got the point...
    Can't be too sure. He never posted after that 'Thanks'. The others must have confused him with their maths

  12. #12
    Join Date
    May 2007
    Location
    knoxville
    Posts
    2,873
    Mentioned
    7 Post(s)
    Quoted
    70 Post(s)

    Default

    Quote Originally Posted by FEAR View Post
    Can't be too sure. He never posted after that 'Thanks'. The others must have confused him with their maths
    yeah, we here at SRL are math geniuses
    <TViYH> i had a dream about you again awkwardsaw
    Malachi 2:3

  13. #13
    Join Date
    Jan 2008
    Location
    Ontario, Canada
    Posts
    7,805
    Mentioned
    5 Post(s)
    Quoted
    3 Post(s)

    Default

    SCAR Code:
    var
      timerInt: Integer;
    begin
      repeat
        TimerInt := GetTimeRunning + 30000;
        DoStuff;
        while (getTimeRunning < TimerInt) do
          Wait(1);
      until False;
    end.

    That will do something ~30s depending on how long doStuff takes.
    Writing an SRL Member Application | [Updated] Pascal Scripting Statements
    My GitHub

    Progress Report:
    13:46 <@BenLand100> <SourceCode> @BenLand100: what you have just said shows you 
                        have serious physchological problems
    13:46 <@BenLand100> HE GETS IT!
    13:46 <@BenLand100> HE FINALLY GETS IT!!!!1

  14. #14
    Join Date
    Mar 2008
    Location
    New Jersey
    Posts
    1,673
    Mentioned
    1 Post(s)
    Quoted
    9 Post(s)

    Default

    oops, I did 30 minutes, my bad lol.

    And I already knew 2+2=22 (just kidding), that's why I put 5, cause he wants an infinite loop


    I like nava's way, it does stuff and waits the amount of time left from the 30 secs, assuming it hasn't been 30 secs yet from doing stuff.

  15. #15
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    I dont understand what was wrong with the original posters way ?

  16. #16
    Join Date
    Jun 2007
    Location
    Wednesday
    Posts
    2,446
    Mentioned
    3 Post(s)
    Quoted
    1 Post(s)

    Default

    I may just be picky, but another way would be
    SCAR Code:
    var
      t: Integer;
    begin
      repeat
        t := GetSystemTime;
        DoStuff;
        t := 30000 - (GetSystemTime - t);
        if t > 0 then
          Wait(t);
      until false;
    end.
    A lot less wait calls and it should have, at most, <2ms over waiting depending on if/how much it takes to call Wait and process the second t := line. The positive t check is probably unneeded, but I like to have it in.

    Oh and the problem with the original suggestion was that if DoStuff took 5 seconds, then it would only call it every 35 seconds due to the 5 second for DoStuff and the 30 seconds for Wait().
    By reading this signature you agree that mixster is superior to you in each and every way except the bad ways but including the really bad ways.

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
  •