Confused about finding library [v2 documentation update required] Topic is solved

Share your ideas as to how the documentation can be improved.
martinPQ
Posts: 9
Joined: 23 Jul 2017, 12:17

Confused about finding library [v2 documentation update required]

Post by martinPQ » 31 Dec 2022, 12:40

[Moderator note: Topic moved and title edited after discussion below.]

Hi.
In v1 this code works like a charm.

Code: Select all

#Requires AutoHotkey v1.1.20
SetWorkingDir %A_ScriptDir%
myLib_func1()
In v2 this code does not.

Code: Select all

#Requires AutoHotkey v2.0
SetWorkingDir(A_ScriptDir)
myLibv2_func1()
I get this message:
Warning: This variable appears to never be assigned a value.
Specifically: global myLibv2_func1


But it does work if I add this line: #include <myLibv2>

Code: Select all

#Requires AutoHotkey v2.0
SetWorkingDir(A_ScriptDir)
#include <myLibv2>
myLibv2_func1()
The v2 documentation states: https://www.autohotkey.com/docs/v2/Scripts.htm#lib
... If a match is still not found and the function's name contains an underscore (e.g. MyPrefix_MyFunc), the program searches both libraries for a file named MyPrefix.ahk and loads it if it exists. This allows MyPrefix.ahk to contain both the function MyPrefix_MyFunc and other related functions whose names start with MyPrefix_.
Essentially the same in v1.

What am I doing wrong?

swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: Confused about finding library

Post by swagfag » 31 Dec 2022, 13:09

this page reads like gibberish(what "function's name" ???). probably not edited very well to reflect the current behavior
anyway, auto-include isnt a thing in v2 anymore. the relevant passage is here https://www.autohotkey.com/docs/v2/v2-changes.htm#functions
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.

User avatar
boiler
Posts: 17328
Joined: 21 Dec 2014, 02:44

Re: Confused about finding library

Post by boiler » 31 Dec 2022, 14:41

Moving this thread to “Suggestions on documentation improvements” so this can be put on this list of things to update, although I believe it’s already known sections like this require significant updating.


Post Reply

Return to “Suggestions on Documentation Improvements”