Script exit after last action

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Lukk54
Posts: 9
Joined: 06 Mar 2021, 04:09

Script exit after last action

Post by Lukk54 » 21 Apr 2021, 02:37

Any ideas why script below will exit after last action and will not repeat twice? thanks. if i delete loop it still exit script after last action.

Code: Select all

l::
loop, 2
{
coordMode,pixel
ImageSearch,ix,iy,0,0,1920,1080, onlinevsichni.png
if !ErrorLevel
{
	Mousemove, ix, iy
	Sleep 10
	Click
}
else
{
	ImageSearch,ix,iy,0,0,1920,1080, awayvsichni.png
	if ErrorLevel
		ImageSearch,ix,iy,0,0,1920,1080, offlinevsichni.png
        if ErrorLevel
                ImageSearch,ix,iy,0,0,1920,1080, nic.png
	if !ErrorLevel
		Mousemove, ix, iy
	        Sleep 10
	        Click
}
send h
h::
Sleep 500
ImageSearch,ix,iy,0,0,1920,1080, tecky.png
if !ErrorLevel {
    Mousemove, ix, iy
    Sleep 10
    Click
}
send v
v::
Sleep 500
ImageSearch,ix,iy,0,0,1920,1080, unfriend.png
if (ix) {
    Mousemove, ix, iy
    Sleep 10
    Click
}
Send j
j::
Sleep 500
ImageSearch,ix,iy,0,0,1920,1080, jenom.png
if !ErrorLevel
{
    Mousemove, ix, iy
    Sleep 10
    Click
}
else
{
MouseMove, 0, 30, 0, R
Sleep 10
Click
}
esc::ExitApp
Sleep, 5000
}
return
[Mod edit: [code][/code] tags added.]
User avatar
boiler
Posts: 17080
Joined: 21 Dec 2014, 02:44

Re: Script exit after last action

Post by boiler » 21 Apr 2021, 07:31

For the { that is the start of your loop:

Code: Select all

l::
loop, 2
{
The } below is the bottom of your loop. Two lines before it gets there, there is a line executing ExitApp. That is why it is exiting the app. It executes that line even though it has a hotkey label.

Code: Select all

esc::ExitApp
Sleep, 5000
}
return

Even if that command wasn’t ExitApp, it would still terminate the loop with a single-line hotkey there, such as esc::Sleep, 100. That is because a single-line hotkey has an implicit return in it. It’s the equivalent of this:

Code: Select all

esc::
Sleep, 100
return

So you should move your esc::exitapp hotkey to the bottom of the script, outside of the loop.
Post Reply

Return to “Ask for Help (v1)”