Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific prog

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
GabeTheGiant
Posts: 3
Joined: 10 Jun 2018, 18:14

Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific prog

13 Jun 2018, 08:48

Here's some perspective:

I am trying to make a script in which a timer runs separately from the main routine. When the main routine is running correctly, it will detect certain actions(whether it be color, movement, or code) and every TRUE statement will be sent to the time to make it start from the beginning(without setting off the timer). If the timer ends, it will be sent to another subprogram that should fix the actual window/program that is running and restart the script.

I have almost the entire coding except I cannot for the life understand the settimer instructions on the command help guide thingy.
User avatar
Hellbent
Posts: 2109
Joined: 23 Sep 2017, 13:34

Re: Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific

14 Jun 2018, 02:02

Hope this helps.

Code: Select all

#SingleInstance Force
Start_Time:=A_TickCount
SetTimer,test,10000
return

; To test this, run the script and then let it show the first tooltip. After that, press numpad 1 every 2-3 seconds for about 20 seconds.
; As you will see, the next time the tooltip shows the time won't be 20000, but rather it will be 10000 after the last time you pressed 
; numpad 1, thus showing it was reset each time you pressed numpad 1.

test:
	Tooltip,% A_TickCount - Start_Time ; This is all that the timer is doing, you can set it to close this/ open that/ whatever.
	return
	
Numpad1::  ; This is the event to restart the timer without triggering it.
	SetTimer,test,10000
	return
	
*ESC::ExitApp	
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific

14 Jun 2018, 17:45

and use a negative time if you want it to tick only once

you can also pass a function instead of a label... I wish people used functions more. all them label based examples make the language look like the 70's
GabeTheGiant
Posts: 3
Joined: 10 Jun 2018, 18:14

Re: Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific

19 Jun 2018, 20:03

Hellbent wrote:Hope this helps.

Code: Select all

#SingleInstance Force
Start_Time:=A_TickCount
SetTimer,test,10000
return

; To test this, run the script and then let it show the first tooltip. After that, press numpad 1 every 2-3 seconds for about 20 seconds.
; As you will see, the next time the tooltip shows the time won't be 20000, but rather it will be 10000 after the last time you pressed 
; numpad 1, thus showing it was reset each time you pressed numpad 1.

test:
	Tooltip,% A_TickCount - Start_Time ; This is all that the timer is doing, you can set it to close this/ open that/ whatever.
	return
	
Numpad1::  ; This is the event to restart the timer without triggering it.
	SetTimer,test,10000
	return
	
*ESC::ExitApp	


Thank you, thank you.....so I assume a timer can't be used to influence another subroutine...all it does it count down?
AHKStudent
Posts: 1472
Joined: 05 May 2018, 12:23

Re: Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific

19 Jun 2018, 20:52

icuurd12b42 wrote:and use a negative time if you want it to tick only once

you can also pass a function instead of a label... I wish people used functions more. all them label based examples make the language look like the 70's
Unless the function is making it easier to manage the program, what are the benefits? I am asking for example for things I only need to use once?

Just curious
icuurd12b42
Posts: 202
Joined: 14 Aug 2016, 04:08

Re: Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific

19 Jun 2018, 23:58

functions are mainly useful to encapsulate the variables the feature you implement requires to work... making it easier to manage the program... also a function can be called more easily...

In any case it's 2018 is the short answer... As much as I enjoyed programming with basic on the vic 20, frankly I would never want to go back there...
Noesis
Posts: 301
Joined: 26 Apr 2014, 07:57

Re: Can someone explain the timer commands in a more comprehensive way than the guide or just enough to make a specific

20 Jun 2018, 01:10

GabeTheGiant wrote: Thank you, thank you.....so I assume a timer can't be used to influence another subroutine...all it does it count down?
Not really. The timer basically repeats whatever code is in the label/function called every x milliseconds, starting x milliseconds (10000 in the example) from when the timer was set.

The hotkey in the example just illustrates that the timer can be reset, i.e the execution of the timer can be postponed, because whenever a timer is set it will always run x milliseconds later, and also repeat every x milliseconds (if a positive period is set, if -ve period is set, it won't repeat, but will run once after the period elapses).

It can be used to influence other subroutines, via variables and/or calling other subroutines, it's not really like a clock timer which simply counts down, it's more like a loop which starts execution at a deferred time, and kind of has an inferred sleep at the end before repeating, (assuming it's set to repeat and also assuming you don't set the period to less time than the time it takes for the routine itself to execute). Another notable thing about a timer is it can interrupt other running threads, which can help simulate the appearance of multi-threading (aka pseudo threading), but that's probably beyond the scope of this request.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: ReyAHK and 254 guests