Author Topic: Simple Timer Tutorial  (Read 13994 times)

0 Members and 1 Guest are viewing this topic.

Offline PauloniusTopic starter

  • Elite
  • *
  • *
  • Posts: 2040
  • Activity:
    0%
  • Reputation Power: 29
  • Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.Paulonius is on the verge of being accepted.
  • Respect: +304
  • Referrals: 1
    • View Profile
Simple Timer Tutorial
« on: January 28, 2014, 07:54:06 AM »
0
Someone was recently asking about waits, so I wrote out a really quick tutorial on timers:

Here is a basic timer routine that sits in a series of quarter second wait for ten seconds:


Code: Select All | Copy To Clipboard

Code: [Select]
Set %Timer #SCNT + 10

While %Timer > #SCNT
     {
     Wait 5
     }
Halt

This timer is limited because the script won't do anything while it is waiting for the timer to expire.


This is a routine that lets you do other stuff until a timer expires every ten seconds, does whatever the timer is controlling, resets the timer, and keeps rolling on the "other stuff"

Code: Select All | Copy To Clipboard
Code: [Select]
Set %Timer #SCNT + 10
Repeat
   {
   ; Do other stuff
   If %Timer < #SCNT
      GoSub Timed_Activity
   Wait 1     ; if you don't have a wait in a loop it eats a lot of processor power.
   }
Until #Charghost = Yes
Halt

Sub Timed_Activity
; Do whatever it is you are timing
Set %Timer #SCNT + 10
Return
This coin declares Caesar is "Dictator for Life." He did serve as Dictator for the remainder of his life, but his life would end only a few weeks after this issue. For Caesar to put his image on coins and essentially declare himself king was too much for Brutus and his republican allies.

"If everything seems under control, you're not going fast enough'
-Mario Andretti

"If everyone is thinking alike, someone isn't thinking."
- General George Patton Jr

Offline camotbik

  • Sr. Member
  • *
  • Posts: 349
  • Activity:
    0%
  • Reputation Power: 3
  • camotbik has no influence.
  • Gender: Male
  • Hello! I'm a UO addict.
  • Respect: +90
  • Referrals: 0
    • View Profile
Re: Simple Timer Tutorial
« Reply #1 on: February 01, 2014, 07:23:44 AM »
0
as i have learned, interactive examples are a bit better to understand. hope you wont mind my input.
Code: [Select]
set %1_timeout 20
set %2_timeout 30
set %first_timer #scnt
set %second_timer #scnt

repeat
  if #scnt > %first_timer
  {
    set %first_timer ( #scnt + %1_timeout )
    event macro 1 1 %1_timeout seconds passed.
  }
  if #scnt > %second_timer
  {
    set %second_timer ( #scnt + %2_timeout )
    event macro 1 1 %2_timeout seconds passed.
  }
  wait 1
until #charghost = yes
stop
What you witness -- is whatver..
uogamers hybrid.

Tags: