"Warning: This variable has not been assigned a value" pops up when calling a function [v2 a116]

Get help for the alpha version of AutoHotkey v2 here. Please state the v2 version you are working with in the title when making a new topic.
User avatar
Tigerlily
Posts: 364
Joined: 04 Oct 2018, 22:31

"Warning: This variable has not been assigned a value" pops up when calling a function [v2 a116]

14 Jul 2020, 00:18

This error seems odd as some Native AHK Functions in this script using 'The "Last Found" Window' (e.g. WinActivate, WinMinimize) work as intended and do not throw this Warning.

However, WinGetTitle without () when nested inside the InStr() function, throws this warning.

code:

Code: Select all

#SingleInstance
SetTitleMatchMode( "Regex" )

#Space::
{	
	MinimizeIt(	"autohotkey",
				"youtube",
				"google play music",
				"gmail",
				"discord" )
}

MinimizeIt( WinTitleList* ){

	for title in WinTitleList	
	if ( WinExist( "i)" title ) )
		{				
			if ( InStr( WinGetTitle, "Google Chrome" ) )
			{
				WinActivate
				
				while ( InStr( WinGetTitle( "A" ), "autohotkey" ) 
				||	    InStr( WinGetTitle( "A" ), "youtube" ) 
				||	    InStr( WinGetTitle( "A" ), "gmail" ) 
				||	    InStr( WinGetTitle( "A" ), "google play music" ) )
				{
					Send( "^{Tab}" )
					Sleep( 50 )
				}
			}	
			else
				WinMinimize
		}
	
}
warning:
Image

Changing WinGetTitle to WinGetTitle() resolved this warning. I'm often confused to when the () is and is not needed when using functions and methods in AHK. seems that generally adding the () is the most reliable, however I would like to know when it is okay to omit the () and when it is not okay. If any one has pointers on this would be much apprecaited.

thanks for reading (*:
-TL
User avatar
kczx3
Posts: 1255
Joined: 06 Oct 2015, 21:39

Re: "Warning: This variable has not been assigned a value" pops up when calling a function [v2 a116]

14 Jul 2020, 14:18

Its edge cases similar to this that I always use parenthesis when calling a function/method. In addition to it feeling and looking more comfortable to the masses due to so many languages using the same syntax construct.

Return to “AutoHotkey v2 Help”

Who is online

Users browsing this forum: w64bit and 9 guests