Thread Tools Display Modes
05-19-17, 12:11 AM   #1
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
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!

Last edited by Layback_ : 05-19-17 at 12:44 AM.
  Reply With Quote
05-19-17, 03:21 AM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Maybe use a simple value, such as true or false. Or even an empty string if that helps somehow.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
05-19-17, 06:22 AM   #3
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by Lombra View Post
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....

Last edited by Layback_ : 05-19-17 at 06:25 AM.
  Reply With Quote
05-19-17, 06:46 AM   #4
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
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.
__________________
  Reply With Quote
05-19-17, 11:44 PM   #5
Layback_
An Onyxian Warder
Join Date: Feb 2016
Posts: 358
Originally Posted by MunkDev View Post
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!!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Storing placeholder value to SV

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off