Possible cause of "Could not close previous instance"?

Ask gaming related questions (AHK v1.1 and older)
Pseudonym
Posts: 1
Joined: 11 Aug 2022, 23:03

Possible cause of "Could not close previous instance"?

Post by Pseudonym » 11 Aug 2022, 23:12

Hi first time poster here so I'm sorry if I mess something up

I'm having trouble closing my code. My Esc hotkey doesn't work and rerunning the script and trying to close it that way throws this "Could not close previous instance" error. It was working before. Did I mess with the wrong line of code or something?

Code: Select all

goodZoneCoordX = 1
goodZoneCoordY = 1
run = 1

g::
ZoneSearch:
ImageSearch, goodZoneCoordX, goodZoneCoordY, 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\proga\Downloads\zone.png
if (ErrorLevel = 1)
{
	Goto, ZoneSearch
}
else
{
	goodZoneCoordX -= 50
	goodZoneCoordY -= 20
}

while (run = 1)
{
	ImageSearch, , , 0, 0, A_ScreenWidth, A_ScreenHeight, C:\Users\proga\Downloads\gameover.png
	if (ErrorLevel = 0)
	{
		run = 0
		break
	}
	else
	{
		MsgBox, Keep Going!
	}

	letterKeyCoordX = 0
	letterKeyCoordY = 0
	
	ImageSearch, , , goodZoneCoordX, goodZoneCoordY, A_ScreenWidth, A_ScreenHeight, C:\Users\proga\Downloads\Z.png
	if (ErrorLevel = 1)
	{
		ImageSearch, , , goodZoneCoordX, goodZoneCoordY, A_ScreenWidth, A_ScreenHeight, C:\Users\proga\Downloads\X.png
		if (ErrorLevel = 1)
		{
			ImageSearch, , , goodZoneCoordX, goodZoneCoordY, A_ScreenWidth, A_ScreenHeight, C:\Users\proga\Downloads\C.png
			if (ErrorLevel = 1) 
			{
				continue
			}
			else
			{
				Send, c
			}
		}
		else
		{
			Send, x
		}
	}
	else
	{
		Send, z
	}
}
return

Esc::ExitApp
return
This script is meant to play a rhythm game for me because I cannot. It's supposed to find the zone to hit (zone.png), then constantly check that area for the three possible notes (Z,X,C) and press the respective keys. And also watch the screen for "Game over" and then stop the while loop.

On a side note, is there a "print"-type statement/command in AHK? I tried using MsgBox to debug but they pause the script which is not helpful. Is there something that'll just output a list of messages or something? I could make and write to a text file but if there's an easier way, I'd love to know.

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

Re: Possible cause of "Could not close previous instance"?

Post by BoBo » 12 Aug 2022, 01:37

Welcome to this forum :)

JFTR…

Code: Select all

Esc::ExitApp ;single line hotkey

Esc:: ;multiple line hotkey
   <whatever command>
   return
On a side note, is there a "print"-type statement/command in AHK? I tried using MsgBox to debug but they pause the script which is not helpful. Is there something that'll just output a list of messages or something? I could make and write to a text file but if there's an easier way, I'd love to know.
a) you could use a ToolTip
b) you could create a concatenated string to display everything in one go (MsgBox, ToolTip) ie ToolTip % clipboard .= <whatever info> "`n" ;keeping everything at the clipboard too
c) log everything into a file
d) you can right-click the scripts tray icon and select 'Open>View'… to review script related details at runtime
e) https://www.autohotkey.com/docs/Scripts.htm#debug
f) https://www.autohotkey.com/docs/AHKL_DBGPClients.htm

Post Reply

Return to “Gaming Help (v1)”