AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Timers

 
Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
B R



Joined: 22 Mar 2009
Posts: 27

PostPosted: Sun Nov 29, 2009 2:37 am    Post subject: Timers Reply with quote

SetTimer has a limitation which I would like to see added - support for multiple timers. I propose:
Code:
SetTimer, Label [, Period, TimerNumber]

This allows you to create separate timers, for instance:
Code:
indexb := indexu := 1
return
#IfWinActive, IRCclient
!b::
Input, name%indexb%,, {Enter}
SendInput, % "/mode #example +b " . name%indexb% . "{Enter}"
SendInput, % "/kick #example " . name%indexb% . "{Enter}"
SetTimer, unban, -60000
indexb++
Return
unban::
SendInput, % "^a^x/mode #example -b " . name%indexu% . "{Enter}"
SendInput, % "/invite " . name%indexu% . " #example{Enter}"
SendInput, % "/privmsg " . name%indexu% . " You can come in now.{Enter}^v"
indexu++
Return
#IfWinActive

It's a ban-for-a-minute IRC thing which unfortunately fails because of the timer issue. The version with SetTimer's extra parameter:
Code:
indexb := indexu := 1
return
#IfWinActive, IRCclient
!b::
Input, name%indexb%,, {Enter}
SendInput, % "/mode #example +b " . name%indexb% . "{Enter}"
SendInput, % "/kick #example " . name%indexb% . "{Enter}"
SetTimer, unban, -60000, %indexb%
indexb++
Return
unban::
SendInput, % "^a^x/mode #example -b " . name%indexu% . "{Enter}"
SendInput, % "/invite " . name%indexu% . " #example{Enter}"
SendInput, % "/privmsg " . name%indexu% . " You can come in now.{Enter}^v"
indexu++
Return
#IfWinActive

This would work, because the timers wouldn't interrupt each other. A workaround for two timers per subroutine (this doesn't work right, I haven't tinkered with it enough, but in any case, I need more than 2 timers):
Code:
temp := 0
!a::
SetTimer, SubRoutine, -60000
SetTimer, gettime, 100
Return
!b::
SetTimer, gettime, off
temporary := temp
temp := 0
Return
SubRoutine:
; Insert normal function here
If temp != 0
 SetTimer, SubRoutine, % temporary
Return
gettime:
temp -= 100
Return


Please either give your support so we can get this in the next release, or show how it can currently be done!
Back to top
View user's profile Send private message
nick



Joined: 24 Aug 2005
Posts: 549
Location: Berlin / Germany

PostPosted: Sun Nov 29, 2009 9:53 am    Post subject: Reply with quote

You might add the name and the current time to a list, which is checked by a timer at regular intervals. If 60 seconds are elapsed, send an invitation and remove the entry from the list.
_________________
nick Wink
Back to top
View user's profile Send private message
B R



Joined: 22 Mar 2009
Posts: 27

PostPosted: Mon Nov 30, 2009 8:21 pm    Post subject: Reply with quote

nick wrote:
You might add the name and the current time to a list, which is checked by a timer at regular intervals. If 60 seconds are elapsed, send an invitation and remove the entry from the list.


Good idea! Here's an untested function (on a Mac, ew. only calls each once, you have to reset it inside the subroutine. not very accurate.):
Code:

SetTimer(Label, Period)
{
 Period := Round(Period, -2)
 List .= Label . " " . Period . "|"
 SetTimer, CheckSetTimer, 100
 Return
 CheckSetTimer:
 Loop, parse, List, |
 {
  StringSplit, CST, A_LoopField, %A_Space%
  CST2 -= 100
  If (CST2 = 0)
  {
   Gosub, %CST1%
   StringReplace, List, List, % A_LoopField . "|"
 }
}
Back to top
View user's profile Send private message
Raccoon



Joined: 02 Jan 2008
Posts: 150
Location: Freenode IRC

PostPosted: Tue Dec 01, 2009 1:27 pm    Post subject: Reply with quote

Original Poster:

You may not be aware, but the "Label" parameter is actually the timer's name. You can have as many timers as you want, each with a different label.

You want multiple timers to call the same sub-routine label? Easy!

Code:
#SingleInstance, Force
#Persistent
#NoEnv

SetTimer, Label1, 1000     ; Every second
SetTimer, Label2, 3600000  ; Every hour

RETURN ; End of Auto-execute section.

Label1:
; This falls through into Label2
Label2:
  ; Stuff that happens when either timer fires.
Return


And you're done!
_________________


Need help right away? Get live support on IRC.
Already have an IRC client installed? /join #ahk
Back to top
View user's profile Send private message
B R



Joined: 22 Mar 2009
Posts: 27

PostPosted: Tue Dec 22, 2009 3:41 am    Post subject: Reply with quote

Good idea, Raccoon! Unfortunately, that doesn't let you use an infinite number of timers, unless you have an infinite number of label declarations. If you don't, then you'll eventually run out.

EDIT: I said that wrong. This topic is about setting multiple timers on a single label. If you use Label1, Label2, etc, you are limited to the number of labels you wrote. I suppose you could have 100 labels and an array stating whether each was free, though. That's probably all I'd need, but a fourth parameter would be even better.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Wish List All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group