Quantcast
WoWInterface - View Single Post - Would it be possible to get value of element during table construction?
View Single Post
07-31-16, 05:16 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 356
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:
  1. G["castbar"] = {
  2.     ["player"] = {
  3.         ["width"] = 350,
  4.         ["height"] = 35,
  5.         ["point"] = {"CENTER", UIParent, "CENTER", 250, -200},
  6.         ["iconSize"] = 35,
  7.         ["spacing"] = 2,
  8.     },
  9. }

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:
  1. G["castbar"] = {
  2.     ["player"] = {
  3.         ["width"] = 350,
  4.         ["height"] = 35,
  5.         ["point"] = {"CENTER", UIParent, "CENTER", 250, -200},
  6.         ["spacing"] = 2,
  7.     },
  8. }
  9. G["castbar"]["player"]["iconSize"] = G["castbar"]["player"]["height"];

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:
  1. G["castbar"] = {
  2.     ["player"] = {
  3.         ["width"] = 350,
  4.         ["height"] = 35,
  5.         ["point"] = {"CENTER", UIParent, "CENTER", 250, -200},
  6.         ["spacing"] = 2,
  7.     },
  8.     ["target"] = {
  9.         ["width"] = G["unitframe"]["target"]["width"],
  10.         ["height"] = 20,
  11.         ["point"] = {"TOP", UIParent, "BOTTOM", 0, 200},
  12.         ["iconSize"] = 20,
  13.     },
  14. }
  15. G["castbar"]["player"]["iconSize"] = G["castbar"]["player"]["height"];
  16. G["castbar"]["target"]["spacing"] = G["castbar"]["player"]["spacing"];
  17. .
  18. .
  19. .

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:
  1. G["castbar"] = {
  2.     ["player"] = {
  3.         ["width"] = 350,
  4.         ["height"] = 35,
  5.         ["point"] = {"CENTER", UIParent, "CENTER", 250, -200},
  6.         ["iconSize"] = G["castbar"]["player"]["height"],
  7.         ["spacing"] = 2,
  8.     },
  9. }

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.

Last edited by Layback_ : 07-31-16 at 05:43 AM.
  Reply With Quote