Thread Tools Display Modes
05-26-18, 08:13 PM   #1
Taet
A Deviate Faerie Dragon
Join Date: Jan 2010
Posts: 17
help with table (savedvariabiles)

i need this table format :
Data={
--[mapID]
[197]={
-- [npcID] = XXX
[91783]=1.94175,
[95861]=1.94175,
[100216]=1.94175,
},
[199]={
[98370]=1.33333,
[98368]=1.33333,
[98366]=1.33333,
},
}
How i add new "mapID" , or "npcID with value" to existing mapID.

I trying with:
local mapID, npcID = 999, 2222
local tmp = {[mapID] = {[npcID] = 1.1111}}
tinsert(Data, tmp)
This dont insert to existing mapID but create new array with to same mapID, and tinsert(Data[mapID], .... bad argument #1
  Reply With Quote
05-26-18, 08:36 PM   #2
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
tinsert is for arrays only.

lua Code:
  1. local data = {}
  2.  
  3. local map, npc = a, 1
  4.  
  5. data[map] = data[map] or {}
  6. data[map][npc] = 1.1
  7. npc = 2
  8. data[map][npc] = 1.2
  Reply With Quote
05-26-18, 08:36 PM   #3
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
It's better to understand if you format the table when typing it out.

Lua Code:
  1. Data={
  2.     -- [mapID]
  3.     [197]={
  4.         -- [npcID] = XXX
  5.         [91783]=1.94175,
  6.         [95861]=1.94175,
  7.         [100216]=1.94175,
  8.     },
  9.     [199]={
  10.         [98370]=1.33333,
  11.         [98368]=1.33333,
  12.         [98366]=1.33333,
  13.     },
  14. }

Adding new keys to a table is as simple as creating any other variable.

Lua Code:
  1. Data[mapID] = {} -- this adds a new mapID with an empty table
  2. Data[mapID] = Data[mapID] or {} -- this adds a new mapID with an empty table if that mapID doesn't already exist
  3. Data[mapID][npcID] = number -- this adds a new npcID with a number (or changes the number of an existing npcID)

Here's what the creation code looks like if you were to add each thing individually.

Lua Code:
  1. Data = Data or {}
  2. Data[197] = Data[197] or {}
  3. Data[197][91783] = 1.94175
  4. Data[197][95861] = 1.94175
  5. Data[197][100216] = 1.94175
  6. Data[199] = Data[199] or {}
  7. Data[199][98370] = 1.33333
  8. Data[199][98368] = 1.33333
  9. Data[199][98366] = 1.33333

And finally, adding your example.

Lua Code:
  1. Data[999] = Data[999] or {}
  2. Data[999][2222] = 1.1111

Last edited by Kanegasi : 05-26-18 at 08:50 PM.
  Reply With Quote
05-26-18, 09:25 PM   #4
Taet
A Deviate Faerie Dragon
Join Date: Jan 2010
Posts: 17
Thanks

WORKING , very very thanks.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Help/Support » help with table (savedvariabiles)

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