Lua error with "attempt to index upvalue 'LANG'(nil value)" I need some help
5 replies, posted
Hi,
I'm running a Slashers server and I got this error in server/user console:
Error in hook HUDPaint: gamemodes/slashers/gamemode/core/lang/cl_lang.lua:14: attempt to index upvalue 'LANG' (a nil value)
stack traceback:
gamemodes/slashers/gamemode/core/lang/cl_lang.lua:14: in function 'GetString'
gamemodes/slashers/gamemode/core/rounds/cl_rounds.lua:35: in function 'fn'
addons/ulib/lua/ulib/shared/hook.lua:109: in function <addons/ulib/lua/ulib/shared/hook.lua:92>
[C]: in function ''
[ERROR]
1. unknown - [C]:-1
The cl_lang.lua file:
local GM = GM or GAMEMODE
local LANG
GM.LANG = {}
function GM.LANG:GetString(key, ...)
return LANG[key] and string.format(LANG[key], ...) or "Unknow key string"
end
local function LoadLanguage(lang)
local languagesPath = "slashers/gamemode/languages"
local files, _ = file.Find(languagesPath .. "/*.lua", "LUA")
LANG = include(languagesPath .. "/" .. slashers_lang_default:GetString() .. ".lua")
for _, v in ipairs(files) do
if v == lang .. ".lua" then
table.Merge(LANG, include(languagesPath .. "/" .. v))
return
end
end
end
local function OnLangChange(convar_name, value_old, value_new)
if value_new != value_old then
LoadLanguage(value_new)
end
end
cvars.AddChangeCallback("gmod_language", OnLangChange)
-- Load user language
do
local cvLang = GetConVar("gmod_language")
LoadLanguage(cvLang:GetString())
end
I don't realy understand the problem. Please help me, you'll get cookies as reward <3
'LANG' is a nil variable but you want it to be a table. Do 'LANG = {}' or just use GM.LANG instead of LANG.
Replace 'LANG' on line 14 with 'self'
I now have new errors with this LANG stuff:
The error:
[ERROR] gamemodes/slashers/entities/entities/sls_generator/shared.lua:14: attempt to index global 'LANG' (a nil value)
1. unknown - gamemodes/slashers/entities/entities/sls_generator/shared.lua:14
2. include -
[C]:-1
3. unknown - gamemodes/slashers/entities/entities/sls_generator/init.lua:14
The file:
local GM = GM or GAMEMODE
local LANG
AddCSLuaFile()
ENT.Type = "anim"
ENT.Base = "base_entity"
ENT.PrintName = LANG:GetString("generator_name")
ENT.Author = "Daryl Winters"
ENT.Information = LANG:GetString("generator_activate")
ENT.Category = "Slashers"
ENT.Spawnable = true
ENT.AdminSpawnable = false
I tried to put "local LANG = {}" or tried to call "self:GetString("generator_name")" but it didn't worked
LANG = include(languagesPath .. "/" .. slashers_lang_default:GetString() .. ".lua")
Make sure the files you are trying to include actually exist, and properly handle missing files or loading failure.
The way you are trying to solve these errors is bad and wrong and will just end up biting you in the ass later, trust me.
I again have some problems with this but this time the error is :
[ERROR] Attempt to index field 'LANG' (a nil value)
Here's the code:
local GM = GM or GAMEMODE
text = GM.LANG:GetString("antisk_time_message")
print(text)
I don't know why this GM.LANG always get me lots of trouble but it's like 1/2 of my errors in the console.
I tried to put before 'local LANG' or 'local LANG = {}' or 'local GM.LANG = {}' but nothing works and this is very annoying
Sorry, you need to Log In to post a reply to this thread.