This script is getting stuck after a while

Ask gaming related questions (AHK v1.1 and older)
Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

This script is getting stuck after a while

Post by Pacifista » 21 Apr 2022, 08:09

Code: Select all

#MaxThreadsPerHotkey 2
NumpadAdd::
	toggle:=!toggle
	While toggle{
	  Send q
	  Sleep 600
	}
Return
[Mod edit: [code][/code] tags added.]

hello, i had been using this in a game. This is making my character use the healing skill as long as cooldown resets to zero.

Now, I'm enabling this when i enter to the fight and after i die and can't turn it off by pressing numpad add or whatever I've assigned the key.

is there a better way to write this script? cuz it somehow cant stop running at some point and whenever i press the corresponding assigned key it won't stop toggling the script.

******************************************
Plus i had another question.

is it possible to close and open the related ahk file with another script?

lets say i use the script above and the script I'm asking will close and open the script above named test.ahk for example

it should close the current running test.ahk file and re run it?

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

Re: This script is getting stuck after a while

Post by Rohwedder » 21 Apr 2022, 08:55

Hallo.
try:

Code: Select all

NumpadAdd::SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
NumpadAdd Up::Send,% toggle?"q":
Since this timer does not require a Sleep, a separate script is usually not needed.
However, if you absolutely want to use two scripts, try:

Code: Select all

FileDelete, NumpadAdd.ahk
Process, Exist
FileAppend, 
(
Process, WaitClose, %ErrorLevel%
ExitApp
NumpadAdd::SetTimer, NumpadAdd Up,`% (toggle:=!toggle)?600:"Off"
NumpadAdd Up::Send,`% toggle?"q":
), NumpadAdd.ahk
Run, NumpadAdd.ahk
Return
q::SoundBeep
Esc::ExitApp
This script writes and runs a 2nd script named NumpadAdd.ahk. With the key NumpadAdd you switch the Timer of NumpadAdd.ahk on and off. This Timer sends q and activates the Hotkey q:: of the main script. As soon as the latter is terminated (e.g. with Escape), NumpadAdd.ahk terminates.

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: This script is getting stuck after a while

Post by Pacifista » 22 Apr 2022, 11:44

Rohwedder wrote:
21 Apr 2022, 08:55
Hallo.
try:

Code: Select all

NumpadAdd::SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
NumpadAdd Up::Send,% toggle?"q":
Since this timer does not require a Sleep, a separate script is usually not needed.
However, if you absolutely want to use two scripts, try:

Code: Select all

FileDelete, NumpadAdd.ahk
Process, Exist
FileAppend, 
(
Process, WaitClose, %ErrorLevel%
ExitApp
NumpadAdd::SetTimer, NumpadAdd Up,`% (toggle:=!toggle)?600:"Off"
NumpadAdd Up::Send,`% toggle?"q":
), NumpadAdd.ahk
Run, NumpadAdd.ahk
Return
q::SoundBeep
Esc::ExitApp
This script writes and runs a 2nd script named NumpadAdd.ahk. With the key NumpadAdd you switch the Timer of NumpadAdd.ahk on and off. This Timer sends q and activates the Hotkey q:: of the main script. As soon as the latter is terminated (e.g. with Escape), NumpadAdd.ahk terminates.
thank you so much.

if i use the script you wrote above is it gonna keep sending specified q press in intervals and won't stuck? cuz the code i pasted here it was getting stuck and cant untoggle..

now for the second part, i needed this code to close and the re open after it gets stuck cuz i had to exit from the running script fast.

Descolada
Posts: 1123
Joined: 23 Dec 2021, 02:30

Re: This script is getting stuck after a while

Post by Descolada » 22 Apr 2022, 12:53

Does this also get stuck eventually?

Code: Select all

toggle := False
Loop {
	if toggle
		Send q
	Sleep 600
}

F1::toggle:=!toggle

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: This script is getting stuck after a while

Post by Pacifista » 24 Apr 2022, 13:40

Descolada wrote:
22 Apr 2022, 12:53
Does this also get stuck eventually?

Code: Select all

toggle := False
Loop {
	if toggle
		Send q
	Sleep 600
}

F1::toggle:=!toggle
i will try to run these ones and get back at you all, thx.

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: This script is getting stuck after a while

Post by Pacifista » 28 Apr 2022, 02:55

it seems

Code: Select all

NumpadAdd::SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
NumpadAdd Up::Send,% toggle?"q":
this code is working like a charm and not getting stuck, thank you so much.

Since this one is working there is no need to make the current running script to close and re run again.

Now i have another code question but i will ask it in another thread thx.

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: This script is getting stuck after a while

Post by Pacifista » 04 Jul 2022, 08:24

is it possible to add keyboard beep sound to this?

Code: Select all

NumpadAdd::SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
SoundBeep, 1500
NumpadAdd Up::Send,% toggle?"q":
SoundBeep, 1500
This way the script still wont beep..

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

Re: This script is getting stuck after a while

Post by Rohwedder » 04 Jul 2022, 09:43

add keyboard beep sound:

Code: Select all

NumpadAdd::
SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
SoundBeep, 1500
Return
NumpadAdd Up::Send,% toggle?"q":""
add timer beep sound:

Code: Select all

NumpadAdd::SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
NumpadAdd Up::
Send,% toggle?"q":""
SoundBeep, 1500,% toggle*100
Return

Pacifista
Posts: 46
Joined: 17 Jan 2022, 16:17

Re: This script is getting stuck after a while

Post by Pacifista » 04 Jul 2022, 12:57

Rohwedder wrote:
04 Jul 2022, 09:43
add keyboard beep sound:

Code: Select all

NumpadAdd::
SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
SoundBeep, 1500
Return
NumpadAdd Up::Send,% toggle?"q":""
add timer beep sound:

Code: Select all

NumpadAdd::SetTimer, NumpadAdd Up,% (toggle:=!toggle)?600:"Off"
NumpadAdd Up::
Send,% toggle?"q":""
SoundBeep, 1500,% toggle*100
Return
Umm thank you but this doesn't seem to be working.


Interestingly it worked after a dozen attempts.

Post Reply

Return to “Gaming Help (v1)”