WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Storing placeholder value to SV (https://www.wowinterface.com/forums/showthread.php?t=55407)

Layback_ 05-19-17 12:11 AM

Storing placeholder value to SV
 
Hi all,

I would venture to say that my project is on its track.

The one thing that I am concerned is storing spell id into SV.

For my case, the spell id is being a key of the table and it would have some data within its table as well.

Here's a brief example.

Lua Code:
  1. MyAuraTracker = { -- SavedVariable
  2.     ["auraIDList"] = {
  3.         ["*"] = { -- Spec
  4.             ["buffs"] = {
  5.                 [2983] = {
  6.                     -- no filter or unit
  7.                 },
  8.                 [1784] = {
  9.                     ["unit"] = "player",
  10.                 },
  11.                 [1966] = {
  12.                     ["filter"] = "RAID|GROUP",
  13.                 },
  14.             },
  15.             ["debuffs"] = {
  16.                 -- same for debuffs
  17.             },
  18.         },
  19.     },
  20. };

Each spell id could have some data like "filter" and "unit" or it could also have none.
(Those data will be used for querying UnitAura).

Well... tbh, most of auras will have no data.

For 2983 I tried to assign nil, but it wasn't possible to do so :(.

So, after all, I've resulted in making sub table for it which I think is a waste of resources.

Could anyone please suggest me a better solution?

Thank you!

Lombra 05-19-17 03:21 AM

Maybe use a simple value, such as true or false. Or even an empty string if that helps somehow.

Layback_ 05-19-17 06:22 AM

Quote:

Originally Posted by Lombra (Post 323465)
Maybe use a simple value, such as true or false. Or even an empty string if that helps somehow.

Hi Lombra,

Yeap, assigning empty string ("") or boolean value were actually one of my alternatives, but decided to abandon those options for some reason which I can't remember why LOL....

I was extremely tired last night and can't remember why haha....

MunkDev 05-19-17 06:46 AM

You'll have to make the choice here yourself. Either waste resources by creating empty tables or waste resources by checking if the index is a table or boolean value on every checkup.

Assigning a table value for a specific key to nil will remove it from the table, rearrange the table structure, and send the old value off to garbage collection. Using true or false will keep the table key, however, if you're using false you have to explicitly check for it when doing a checkup.

It's a fairly common thing in Lua to use lookup tables, where you store the actual value as key and just omit the value. Usually you would use true as value in that case just to keep the table entry.

Layback_ 05-19-17 11:44 PM

Quote:

Originally Posted by MunkDev (Post 323467)
You'll have to make the choice here yourself. Either waste resources by creating empty tables or waste resources by checking if the index is a table or boolean value on every checkup.

Assigning a table value for a specific key to nil will remove it from the table, rearrange the table structure, and send the old value off to garbage collection. Using true or false will keep the table key, however, if you're using false you have to explicitly check for it when doing a checkup.

It's a fairly common thing in Lua to use lookup tables, where you store the actual value as key and just omit the value. Usually you would use true as value in that case just to keep the table entry.

Hi MunkDev,

At this stage, I decided to continue using empty tables as I guess this is the easiest way to maintain my codes.

Thank you for your advice!!


All times are GMT -6. The time now is 10:15 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI