SetTimer not working consistently

Ask gaming related questions (AHK v1.1 and older)
vinilzord
Posts: 41
Joined: 08 Apr 2020, 15:32

SetTimer not working consistently

02 Jan 2021, 14:46

Hi all :D

I have the following script to send F8 every 25seconds, and I really really need to include more hotkeys to improve my gameplay experience.

It's not working 100%. It works fine for a few minutes, but randomly it stops sending F8 (which leaves my character unbuffed and therefore weaker), and also randomly sends F8 with the correct delay after not working for like a full minute.

If it matters, I use win7 64 bits and the game is Ragnarok Online.

Code: Select all

#SingleInstance, Force

$F8:: ;On/Off with key F8 - TRUE SIGHT

If !TF8 := !TF8

{
	SetTimer TF8, Off
	Return
}

SetTimer TF8, 25000

TF8:  ;immediately and every 25 seconds

Send, {F8 down}
Sleep, 500
Send, {F8 up}

Return


CTRL::Suspend, Toggle
INS::Pause, Toggle
SHIFT::Reload



Could you please help me? And as I said I need to include more hotkeys to provide me more buffs, I need it to be consistent 100% of the time ^^

Thanks in advance
User avatar
mikeyww
Posts: 26938
Joined: 09 Sep 2014, 18:38

Re: SetTimer not working consistently

02 Jan 2021, 14:54

Did you intend to have the timer loop inside the hotkey routine?

Re:

If !TF8 := !TF8

You probably did not intend the first !.
vinilzord
Posts: 41
Joined: 08 Apr 2020, 15:32

Re: SetTimer not working consistently

02 Jan 2021, 15:02

@mikeyww

I did in the beginning when sorting out the script, but I'm not sure if it's optimal. What do you think?
User avatar
mikeyww
Posts: 26938
Joined: 09 Sep 2014, 18:38

Re: SetTimer not working consistently

02 Jan 2021, 16:03

Your script looks essentially OK to me, but it's worth noting that if you press F8 twice in a row quickly, the second press will not register.

#MaxThreadsPerHotkey:
If a hotkey has a max of 1 and it is pressed again while its subroutine is already running, the press will be ignored.
I'm not sure whether that is related to your problem, but you could add some beeps or visual indicators of the timer actions to learn more about what is happening with the flow. I would also remove your suspend and pause commands while you are testing, or do something like the following.

Code: Select all

$F8::
If !TF8 := !TF8
{
	SetTimer, TF8, Off
	SoundBeep, 1000, 30
	Return
}
SetTimer, TF8, 25000
SoundBeep, 1500, 30
TF8:
Send {F8 down}
Sleep, 500
Send {F8 up}
Return

CTRL::
Suspend
SoundBeep, 900, 30
Return

INS::
SoundBeep, 700, 30
Pause,, 1
Return
vinilzord
Posts: 41
Joined: 08 Apr 2020, 15:32

Re: SetTimer not working consistently

03 Jan 2021, 14:22

Thanks for replying!

The code above still has the same problem. It works for a few minutes then stops and starts working again ...

I'm clueless
User avatar
mikeyww
Posts: 26938
Joined: 09 Sep 2014, 18:38

Re: SetTimer not working consistently

03 Jan 2021, 17:22

Are you accidentally pausing or suspending the script? That's all I can imagine, other than a conflicting script, high CPU load, or admin issue.

Have you tried the basic concept in a text editor to see if the routine works (works at this end)?

Some programs require a different send mode, such as SendPlay or SendInput.
User avatar
Xtra
Posts: 2750
Joined: 02 Oct 2015, 12:15

Re: SetTimer not working consistently

03 Jan 2021, 17:32

The problem with your approach is you are not checking if the game is ready to accept input or has accepted it.
This can screw things up as you are seeing. Casting speed/cooldowns, latency, lag, high cpu use etc can cause issues.

You will want to rethink your script to prevent timing problems. Take a look at:
PixelGetColor
PixelSearch
ImageSearch
These can fix the issues.
Take a look at the game and say how would i know when its ready to cast/ has been casted.
Then you will know the answer on how to handle it.

HTH
User avatar
mikeyww
Posts: 26938
Joined: 09 Sep 2014, 18:38

Re: SetTimer not working consistently

03 Jan 2021, 17:45

Those are good points. I do not have the game and so do not have a good way to test. Best of luck.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 70 guests