Page 1 of 1

did moving my "documents" directory break the /Libs folder?

Posted: 17 Apr 2024, 12:20
by hemps
Hello,

I am using V2.

In Windows I moved my default Documents directory and I seem to be unable to find/run custom functions from this location
D:\Users\MYUSERNAME\Documents\AutoHotkey\Lib

First I wrote and saved this file (hello.ahk), which works as expected:

Code: Select all

F1::
{
x := "Hello World!"

msgbox X
}


F2:: 
{
	helloWorld()
}

;F3:: 
;{
;	helloWorld2()
;}


;;;;;;;;;;;;;;;;;;;
;; local functions
;;;;;;;;;;;;;;;;;;;

helloWorld() {
	x := "Hello World!"
	msgbox X
	return 
}
Then I wrote and saved helloWorld2.ahk which includes the following:

Code: Select all

helloWorld2() {
	x := "Hello World!"
	msgbox X
	return 
}
This function is saved at:
D:\Users\MYUSERNAME\Documents\AutoHotkey\Lib\helloWorld2.ahk

When I uncomment the "F3" lines in the original hello script from that Lib I get the following error:

Warning: This variable appears to never be assigned a value.

Specifically: local helloWorld2

012: }
015: {
▶ 016: helloWorld2()
017: }
024: {

For more details, read the documentation for #Warn.


To test I tried to directly include the function with the line:
#Include "D:\Users\MYUSERNAME\Documents\AutoHotkey\Lib\helloWorld2.ahk"

That worked as expected.

When I changed the default "Documents" director, did that break the default access to the "\Documents\AutoHotkey\Lib\" location , or am I doing something else wrong?

Re: did moving my "documents" directory break the /Libs folder?  Topic is solved

Posted: 17 Apr 2024, 13:50
by boiler
From the v2 documentation:
Changes from v1.1 to v2.0 > Functions wrote:Scripts are no longer automatically included from the function library (Lib) folders when a function call is present without a definition, due to increased complexity and potential for accidents (now that the MyFunc in MyFunc() can be any variable). #Include <LibName> works as before. It may be superseded by module support in a future release.

Re: did moving my "documents" directory break the /Libs folder?

Posted: 17 Apr 2024, 14:04
by hemps
Thank you for that @boiler

A followup question. According to the docs (https://www.autohotkey.com/docs/v2/lib/_Include.htm) I should be able to access my functions by naming the directory they live within.
The docs show:

Code: Select all

https://www.autohotkey.com/docs/v2/lib/_Include.htm
So then if would expect this to work:

Code: Select all

#Include "D:\Users\MYUSERNAME\Documents\AutoHotkey\Lib"
But it seems to give me the same error:
Warning: This variable appears to never be assigned a value.

Please advise, thank you.

Re: did moving my "documents" directory break the /Libs folder?

Posted: 17 Apr 2024, 14:32
by boiler
hemps wrote:
17 Apr 2024, 14:04
According to the docs (https://www.autohotkey.com/docs/v2/lib/_Include.htm) I should be able to access my functions by naming the directory they live within.
No, it does not say it allows access to all functions in that directory simply by specifying the folder. It says it changes the working directory for subsequent occurrences of #Include. I can't tell exactly what you are referring to because you didn't provide an excerpt from the page; you just provided the URL again in place of where you apparently meant to quote a section from that page.

Re: did moving my "documents" directory break the /Libs folder?

Posted: 17 Apr 2024, 14:37
by hemps
Thank you, again, @boiler

Is there a way to access all the functions within a folder as I could do under v1 when storing the functions in the /autohotkey/lib folder?

Re: did moving my "documents" directory break the /Libs folder?

Posted: 17 Apr 2024, 14:39
by boiler
No, as noted in my first post, that is a change from v1.1 to v2.0.

Re: did moving my "documents" directory break the /Libs folder?

Posted: 17 Apr 2024, 16:17
by Seven0528
 #Include directives can include other #Include directives. In the past, I often included all frequently used libraries in one ahk file and then included that ahk file, but that's not recommended, personally. Especially as programs become more complex, it's better to manage by explicitly including files.