ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Tutorials => Topic started by: Paulonius on January 28, 2014, 07:54:06 AM

Title: Simple Timer Tutorial
Post by: Paulonius on January 28, 2014, 07:54:06 AM
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
Title: Re: Simple Timer Tutorial
Post by: camotbik on February 01, 2014, 07:23:44 AM
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