Hello! Hopefully I'm missing something simple here. I have a list of scripts that I want to make mutually exclusive. Here's the example - please note that they have varying numbers of zero-width spaces before the filename so that Windows will sort them in the "correct" order.
EDIT: I just tested with some example scripts that don't have the zero-width spaces, and that's replicating the exact same issues.
Code: Select all
Character1 := A_ScriptDir "\Example 1.ahk"
Character2 := A_ScriptDir "\Example 2.ahk"
Character3 := A_ScriptDir "\Example 99.ahk"
Character4 := A_ScriptDir "\Example 10.ahk"
Character5 := A_ScriptDir "\Example.ahk"
Previously, the way I was making them mutually exclusive was by having a list of 'if' statements that I would copy into each script before deleting the one that corresponded with the script it was in:
Code: Select all
if WinExist(Character1) ; Delete the two lines that correspond with *this* script.
WinClose
if WinExist(Character2)
WinClose
if WinExist(Character3)
WinClose
if WinExist(Character5) ; Skipping Character 4 as though this were in the script for Example 10.
WinClose
This method works perfectly, even with the zero-width spaces in script names. However, as the list of scripts has grown, this has become untenable, and I wanted to use a loop to clean up the code. Here's the loop that I have, which seems to be working, just not closing the scripts.
Code: Select all
ScriptNumber := 1
loop 15 ; Increase this number if you add more scripts.
{
if ScriptNumber = 0 ; Change this for the number that corresponds with *this* script.
{
++ScriptNumber
}
else
{
Current := ("Character" Scriptnumber)
if WinExist(Current)
WinClose
++ScriptNumber
}
}
When I used a MsgBox to check the value of 'Current,' it was updating and counting correctly. So, can WinExist not be used with a concatenated variable like that, or is my syntax wrong, or...?
Thanks for any input you might have!
Edit: Also, here's the header that I've got:
Code: Select all
#Requires AutoHotkey v2.0
#SingleInstance Force
DetectHiddenWindows(true)
And this comes after the whole mutual exclusivity bit, which I think shouldn't be interfering, but hey:
Code: Select all
^!+x::ExitApp()
#HotIf WinActive("Game")