Would it be possible to get value of element during table construction?
Hi again all,
The title says everything. I was trying to create a configuration table for my castbar and just got a question regarding table construction. Let's say I have a simple table like this: Lua Code:
As you can see, height and iconSize have a same value and this is because I would like the icon to be the same size as the castbar's height. Of course, I could do something like Lua Code:
and this will definitely work without any issues. However, as I add target's castbar, targettarget's castbar, party1's castbar and so on, this would look ugly and would be complex for me to manage with. e.g: Lua Code:
I also tried something like the following and this doesn't seem to be working. I'm guessing that this is because the table G["castbar"] does not exist yet, since it is on the way of its construction. Lua Code:
To gain some idea, I have gone through the official references, but could have not found anything close to this... Would there be any possible approach to achieve something similar to the above? Thank you. |
Why don't you just construct your icon like this?
Lua Code:
Then you can ditch the variable too. |
Working on the previous solution, maybe:
Lua Code:
then when using the configuration do something like: Lua Code:
|
Quote:
But, if possible, I would like to keep them as a two separate variables. For now, height and iconSize could be the same values, but for some cases I could give some variations on them. Quote:
So... there is no such a straight-forward way to achieve this, right? |
Quote:
|
Quote:
I'll have a go with it! Thank you |
Why not have it default to height if iconSize is absent (nil)?
You can then use a fallback assignment like the following: Code:
local height = G["castbar"]["player"]["height"]; |
Quote:
|
All times are GMT -6. The time now is 08:35 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI