upvalue functions and default key values of an array
Hi,
I'd like to ask a couple of questions. 1) Is fine to upvalue a function using it's same name ? Something like: Lua Code:
I usually wrote something like: Lua Code:
It obviusly works but in this way I dont have the syntax color of the editor :/ :) Does it have some dark side effects ? 2) Another question. Until now I usually initialize (wrongly) my vars in this way. Lua Code:
Now I have understood better that the vars are overwritten during ADDON_LOADED event so I can write in this way: Lua Code:
What I want to ask ... Is there a better way to write values in an array if they are null ? Or the Lua Code:
for every key is a good enough solution ? Thanks so much to everyone and patience. |
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 = { Code:
local format = string.format Lua Code:
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. |
Quote:
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 :) Quote:
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:
for every keys. Probably we can use two tables. MYADDON_CFG and MYADDON_CFG_DEFAULTS and then Lua Code:
I have to check. Thanks so much for your kind reply. They are always precious. |
I think in this way it could be fine to write and it seems to works to :)
Lua Code:
|
Uhm I have to rewritten it in this way:
Lua Code:
or the values = false are overwritten by defaults like they (I wrongly supposed) were nil. And it is not what I am looking for. In this way it works. |
It doesn't check if the GMEXP_CFG exists so on a new install where the game has created the placeholder (GMEXP_CFG = nil) but you haven't assigned a table to it, this will fail.
Lua Code:
|
Quote:
I am doing this in the first part of the addon ... Lua Code:
... because I didn't think I couldn't move them there :) Now that I know I can I'll move them there. Thanks so much Fizzlemizz. |
All times are GMT -6. The time now is 05:42 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI