A_TickCount multiple times in a script

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Jezza
Posts: 3
Joined: 17 May 2022, 20:18

A_TickCount multiple times in a script

Post by Jezza » 21 May 2022, 00:17

Can A_TickCount be used multiple times in a script? I can get it to work for the first but the second wont work

Code: Select all

#Persistent

 If DllCall("LoadLibrary", "str", "PacDrive32.dll")
  If DllCall("PacDrive32.dll\PacInitialize")

CoordMode, Pixel
Sub1 := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
SetTimer, LED1, 100
LED1:
PixelGetColor, thisColor, -574, 327
If (thisColor != targetColor)
 Sub1 := A_TickCount
If (A_TickCount - Sub1 > minTime)
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,0)
else
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,1)

CoordMode, Pixel
Sub2 := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
SetTimer, LED2, 100
LED2:
PixelGetColor, thisColor, -652, 327
If (thisColor != targetColor)
 Sub2 := A_TickCount
If (A_TickCount - Sub2 > minTime)
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,0)
else
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,1)
[Mod edit: Fixed [code][/code] tags. They go around the code.]

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: A_TickCount multiple times in a script

Post by Rohwedder » 21 May 2022, 00:53

Hallo,
I added SoundBeeps for both SetTimer. The second Timer cannot work because it is constantly reinitialized by the first Timer.
Try:

Code: Select all

#Persistent

 If DllCall("LoadLibrary", "str", "PacDrive32.dll")
  If DllCall("PacDrive32.dll\PacInitialize")

CoordMode, Pixel
Sub1 := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
SetTimer, LED1, 100
SoundBeep, 1000, 20 ;<<<<<<<<<<<<<<<<<<
LED1:
PixelGetColor, thisColor, -574, 327
If (thisColor != targetColor)
 Sub1 := A_TickCount
If (A_TickCount - Sub1 > minTime)
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,0)
else
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,1)

CoordMode, Pixel
Sub2 := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
SetTimer, LED2, 100
SoundBeep, 2000, 20 ;<<<<<<<<<<<<<<<<<<
LED2:
PixelGetColor, thisColor, -652, 327
If (thisColor != targetColor)
 Sub2 := A_TickCount
If (A_TickCount - Sub2 > minTime)
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,0)
else
DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,1)

Jezza
Posts: 3
Joined: 17 May 2022, 20:18

Re: A_TickCount multiple times in a script

Post by Jezza » 22 May 2022, 00:42

That's just the same thing with beeps :D

Thanks for the response though, any other ideas to make the second one work?

Have tried different methods to get led to turn off if pixel doesn't turn yellow for 2 seconds (which is what I'm actually trying to achieve) but to no avail...

Rohwedder
Posts: 7551
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: A_TickCount multiple times in a script

Post by Rohwedder » 22 May 2022, 03:26

Perhaps??:

Code: Select all

#Persistent
DllCall("LoadLibrary", "str", "PacDrive32.dll")
DllCall("PacDrive32.dll\PacInitialize")
CoordMode, Pixel
Sub1 := A_TickCount, targetColor := "0xC0C0C0", minTime := 2000
SetTimer, LED1, 200
Sleep, 100
Sub2 := A_TickCount
SetTimer, LED2, 200
LED1:
PixelGetColor, thisColor, -574, 327
If (thisColor != targetColor)
	Sub1 := A_TickCount
If (A_TickCount - Sub1 > minTime)
	DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,0)
else
	DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,9,Int,1)
Return
LED2:
PixelGetColor, thisColor, -652, 327
If (thisColor != targetColor)
	Sub2 := A_TickCount
If (A_TickCount - Sub2 > minTime)
	DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,0)
else
	DllCall("PacDrive32.dll\PacSetLEDState",Int,0,Int,8,Int,1)
Return

Post Reply

Return to “Ask for Help (v1)”