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

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
hemps
Posts: 3
Joined: 17 Apr 2024, 10:56

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

Post by hemps » 17 Apr 2024, 12:20

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?
User avatar
boiler
Posts: 17142
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 17 Apr 2024, 13:50

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.
hemps
Posts: 3
Joined: 17 Apr 2024, 10:56

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

Post by hemps » 17 Apr 2024, 14:04

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.
User avatar
boiler
Posts: 17142
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 17 Apr 2024, 14:32

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.
hemps
Posts: 3
Joined: 17 Apr 2024, 10:56

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

Post by hemps » 17 Apr 2024, 14:37

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?
User avatar
boiler
Posts: 17142
Joined: 21 Dec 2014, 02:44

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

Post by boiler » 17 Apr 2024, 14:39

No, as noted in my first post, that is a change from v1.1 to v2.0.
User avatar
Seven0528
Posts: 378
Joined: 23 Jan 2023, 04:52
Location: South Korea
Contact:

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

Post by Seven0528 » 17 Apr 2024, 16:17

 #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.
  • English is not my native language. Please forgive any awkward expressions.
  • 영어는 제 모국어가 아닙니다. 어색한 표현이 있어도 양해해 주세요.
Post Reply

Return to “Ask for Help (v2)”