That's most likely a timing issue.
Calling LibTimer:Start() directly will look up the global variable then and there.
Assigning LibTimer to a local LT and then calling LT:Start() right in the same function will have the same effect:
Lua Code:
function myFunc()
local LT = LibTimer
LT:Start()
end
The problem is, when you assign local LT at the start of the file, it is looking up LT at a different time than when you call LT:Start():
Lua Code:
local LT = LibTimer -- looks at LibTimer once when the file is loaded
function myFunc()
LT:Start() -- LT is now nil
end
To avoid that issue, you will have to understand when LibTimer is assigned to the global variable and then make sure your local is only assigned afterwards.
In most cases it should be enough to add the library to your DependsOn in the addon manifest. That way the game will always load library files before your own addon files.
However some libraries may not initialize during file load, but instead wait for an event like EVENT_ADD_ON_LOADED or EVENT_PLAYER_ACTIVATED or something else, which only occurs after files have loaded.
In that case you'll have to move the code from the root of your file into a function and call that function after the library has been fully loaded.
Such special cases are usually explained in the library description though.