Originally Posted by Fizzlemizz
1. You can't
local string.format = string.format
directly, you would need a local "string" table to assign the functions to (a bit self defeating):
Code:
local string = {
format = string.format,
}
but you can lessen your typing depending on preference .
Code:
local format = string.format
|
Hi Fizzlemizz,
now I understand why I usually never found upvalued with same name.
And in my case that I string.format a couple of vars I think I dont need at all
2.
Lua Code:
if event == "PLAYER_LOGIN" then if not MYADDON_CFG then -- doesn't exist so add defaults MYADDON_CFG = { KEY1 = true, KEY2 = "var2", KEY3 = 3, } end end
PLAYER_LOGIN only fires once after all addons have loaded including their saved variables. The game knows most things about the character loading that don't requiring a server request at this point.
|
Thanks for input on PLAYER_LOGIN vs ADDON_LOADED event but here the question is a little bit different
I am not asking to use defaults for ALL keys if not exist MYADDON_CFG but I am asking for a different approach to put a default value when happens that some of these keys has nil values (for example a new config).
For this reason I use:
Lua Code:
if MYADDON_CFG["KEY1"] == nil then MYADDON_CFG["KEY1"] = true end
for every keys.
Probably we can use two tables.
MYADDON_CFG and MYADDON_CFG_DEFAULTS and then
Lua Code:
for k in pairs(MYADDON_CFG_DEFAULTS) do
MYADDON_CFG[k] = MYADDON_CFG[k] or MYADDON_CFG_DEFAULTS[k]
end
I have to check.
Thanks so much for your kind reply. They are always precious.