View Single Post
04-06-20, 11:12 AM   #3
gmarco
An Onyxian Warder
 
gmarco's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2009
Posts: 362
Originally Posted by Fizzlemizz View Post
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:
  1. if event == "PLAYER_LOGIN" then
  2.     if not MYADDON_CFG then -- doesn't exist so add defaults
  3.         MYADDON_CFG = {
  4.             KEY1 = true,
  5.             KEY2 = "var2",
  6.             KEY3 = 3,
  7.         }
  8.     end
  9. 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:
  1. 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:
  1. for k in pairs(MYADDON_CFG_DEFAULTS) do
  2.     MYADDON_CFG[k] = MYADDON_CFG[k] or MYADDON_CFG_DEFAULTS[k]
  3. end

I have to check.

Thanks so much for your kind reply. They are always precious.
__________________
This is Unix-Land. In quiet nights, you can hear the Windows machines reboot.
  Reply With Quote