Thread Tools Display Modes
05-30-10, 04:42 PM   #1
clowcadia
A Chromatic Dragonspawn
Join Date: Apr 2010
Posts: 186
working with table.insert and pairs(tables).. confused

i have made a lua code trying to work out something on my addon but it self doesnt give me the right values when i print

Code:
loadCount=0
tableCount=0
loadCount=loadCount + 1


loadedTable = loadedTable or {}
loadedTable = { [loadCount] = {} }

for key,value in pairs(loadedTable) do
    print(key,value)
    if value == 0 then
        tableCount=tableCount + 1
        tableCount = tableCount {}
        tableCount = { "dude" }
        table.insert( loadedTable, tableCount )
        if ( type(key) == "table" ) then
            for key1,value1 in pairs(value) do 
                print(key1,value1)
            end
        end
    end
end
and i get this , instead of dude
1 table: 0x62e560

Last edited by Seerah : 05-30-10 at 04:53 PM. Reason: properly formatted code block so I could read it better
  Reply With Quote
05-30-10, 04:55 PM   #2
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,929
Not quite right. key is the 1 value is the table. So you need to do the type test on value. Which is why value is inside the pairs() function. You were almost there.

Also, you are using the same variable to hold different values. The first line makes sense for what it is doing but the next two are doing something that then replaces the number you just set it up as.

tableCount=tableCount + 1
tableCount = tableCount {}
tableCount = { "dude" }
__________________


Characters:
Gwynedda - 70 - Demon Warlock
Galaviel - 65 - Resto Druid
Gamaliel - 61 - Disc Priest
Gwynytha - 60 - Survival Hunter
Lienae - 60 - Resto Shaman
Plus several others below level 60

Info Panel IDs : http://www.wowinterface.com/forums/s...818#post136818
  Reply With Quote
05-30-10, 04:55 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Well, for starters, you're only reference to "dude" will never be called because that block only runs if value is 0.

There are other things in there, but that should hopefully help you get started.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
05-30-10, 05:03 PM   #4
clowcadia
A Chromatic Dragonspawn
Join Date: Apr 2010
Posts: 186
thank you guys, i shall try that. (if u are willing to answear this, but is this a valid question to be posted. because i understand some things can be found in documentations and stuff. but i looked around and read around nothing to guide me in the right direction wi what i am trying)
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » working with table.insert and pairs(tables).. confused


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