errors and warnings / names / W1034
W1034 warning
Name read at load time but only defined at run time
- area
- names (x1xxx)
- fails the build
- with --deny-warnings
A file reads a global (or an addon-namespace field) while it loads, but the
only definitions of that name run later, inside functions such as event
handlers. When the file loads in game the value is still nil. Define the
name at the top level of its file, or move the read into code that runs
after the definition (the same event, or a later one).
Example
local frame = CreateFrame("Frame")frame:RegisterEvent("PLAYER_LOGIN")frame:SetScript("OnEvent", function() MyAddonDB = {}end)print(MyAddonDB)local frame = CreateFrame("Frame")frame:RegisterEvent("PLAYER_LOGIN")frame:SetScript("OnEvent", function() MyAddonDB = {}end)local frame = CreateFrame("Frame")frame:RegisterEvent("PLAYER_LOGIN")frame:SetScript("OnEvent", function() print(MyAddonDB)end)The compiler reports it like this:
warning[W1034]: `MyAddonDB` is read while the file loads, but only defined later (inside functions that run at run time) ┌─ src/b.lua:1:7 │ 1 │ print(MyAddonDB) │ ^^^^^^^^^ read at load time
Related codes
| code | message |
|---|---|
| W1033 | Load order cannot be determined (dynamic names, several writers, external names); files keep their source order |
| E1014 | Import or usage cycle containing a load-time edge (run-time-only cycles are allowed) |
Offline
$ wowlua explain W1034 W1034 (warning): Name read at load time but only defined at run time