Thread Tools Display Modes
04-24-08, 04:38 PM   #1
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Unhappy Table help

Hi again, i have a (for most) quite simple question;

How do i print three separate values from three different tables into a line?
And as a follow-up question, i need to do this on 40 lines with new data on each line, how do i do this?
Summary:
  • Three (3) Tables
  • 40 lines of data
  • One piece of data from each table on each line
Btw, i'm writing it all in lua if it helps..
Please help me!
  Reply With Quote
04-24-08, 06:06 PM   #2
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by hipjipp View Post
Hi again, i have a (for most) quite simple question;

How do i print three separate values from three different tables into a line?
And as a follow-up question, i need to do this on 40 lines with new data on each line, how do i do this?
Summary:
  • Three (3) Tables
  • 40 lines of data
  • One piece of data from each table on each line
Btw, i'm writing it all in lua if it helps..
Please help me!
not totally sure i understood that right, but:

Code:
for i = 1, 40 do
     myOutputFunction(table1[i]..", "..table2[i]..", "..table3[i]..".")
end
  Reply With Quote
04-24-08, 06:34 PM   #3
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Originally Posted by Akryn View Post
not totally sure i understood that right, but:

Code:
for i = 1, 40 do
     myOutputFunction(table1[i]..", "..table2[i]..", "..table3[i]..".")
end
I tried it, it works, but i have no idea on examples on how to make an output function (yes, i'm a newb at coding lua). i get an error after i tried a few things;
Code:
attempt to concatenate field '?' (a nil value)
I'm currently trying to output it through this
Code:
local text = addon:CreateFontString(nil, "OVERLAY")
text:SetFont(font, 14)
for i = 1,39 do
    text:SetText(lvl[i]..", "..h[i]..", "..loc[i]..".")
end
If anyone knows, how would i call the tables from another file? I'd like to keep the core clean, but i can't atm since the tables are in it.. :P

Thanks for the help btw.
  Reply With Quote
04-24-08, 08:25 PM   #4
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
if you want to access the tables from another lua file, you need to either make them global (which is ugly) or create a namespace for them. you can use the frame if you want, or else any global table. for example
Code:
addon.table1 = {stuff}
which can then be accessed globally as [the frame's actual name].table1, without polluting the global namespace.

here's a simple function to output to the chat frame, if that's what you want to do:
Code:
local function cout(msg)
	if(DEFAULT_CHAT_FRAME) then
		DEFAULT_CHAT_FRAME:AddMessage(msg, 0.0, 1.0, 0.0, 1.0)
	end
end
your nil error means that one of your tables either has nil values or is shorter than expected. here's a bit more robust version
Code:
for i = 1,39 do
    local lvlL, hL, locL = (tostring(lvl[i]) or "?"), (h[i] or "?"), (loc[i] or "?")
    cout( ("%s, %s, %s."):format(lvlL, hL, locL) )
end

Last edited by Akryn : 04-24-08 at 08:30 PM.
  Reply With Quote
04-25-08, 03:47 AM   #5
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Thanks for the code, works like a charm. I found that my nil was created by me missing out in one table.. accedently skipped one entry..

Your Cout code is just amazing (as a learning c++ student :P), but i don't need the text in my chat box, i need it in a frame i created.

Please keep it up. =)
  Reply With Quote
04-25-08, 08:05 AM   #6
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by hipjipp View Post
i need it in a frame i created.
ah ok. are you wanting to have all of the values visible at once? if so you could do something like:
Code:
local lastLine = nil
for i = 1,39 do
    local text = addon:CreateFontString(nil, "OVERLAY")
    text:SetFont(font, 14)
    local lvlL, hL, locL = (tostring(lvl[i]) or "?"), (h[i] or "?"), (loc[i] or "?")
    text:SetText( ("%s, %s, %s."):format(lvlL, hL, locL) )
    text:ClearAllPoints()
    if lastLine then
         text:SetPoint("TOPLEFT", lastLine, "BOTTOMLEFT")
    else
         text:SetPoint("TOPLEFT", addon, "TOPLEFT")
    end
    lastLine = text
end
if you want to change those values later, you'll probably want to store a reference to each fontstring in a table, or as addon.text1/2/3/etc, or something like that
  Reply With Quote
04-25-08, 02:50 PM   #7
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
Thanks for the awesome code! Now all i need to do is figure out how to create tabs (havn't figured out how to write it from wowwiki...
(No need to help me with this unless you want to))..

I really appreciate that there's atleast some helpful people here.. ^^
  Reply With Quote
04-25-08, 04:20 PM   #8
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
tabs are pretty easy actually; they're just buttons that either hide/show elements or re-display text or whatever. for example you could do something like this (and of course there's all sorts of other options for this, this is just a simple example -- also i'm not at home atm so i can't test this, there might be mistakes etc )

Code:
local function OnTabClick(num)
    --do whatever, based on num
end

addon.Tab1 = CreateFrame("Button")
addon.Tab2 = CreateFrame("Button")
local t1, t2 = addon.Tab1, addon.Tab2
--put code here to make the buttons look the way you want them to
t1:SetParent(addon)
t2:SetParent(addon)
t1:SetText("Tab1")
t2:SetText("Tab2")
t1:ClearAllPoints()
t2:ClearAllPoints()
t1:SetPoint("TOPLEFT", addon, "BOTTOMLEFT")
t2:SetPoint("TOPLEFT", t1, "TOPRIGHT")
t1:SetScript("OnClick", function() OnTabClick(1) end)
t2:SetScript("OnClick", function() OnTabClick(2) end)
edit: looking back at that, it won't work quite right (i'm used to doing gui stuff in xml x_x) but it should hopefully be somewhat useful getting started. let us know if you have problems getting it to work

Last edited by Akryn : 04-25-08 at 04:34 PM.
  Reply With Quote
04-25-08, 05:48 PM   #9
hipjipp
A Cliff Giant
 
hipjipp's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 79
I've read and understood the code, even shaped it up a notch, but since i'm still near the bottom of the lua society i have no idea on how to use the "OnTabClick(num)" code.. I know the point of it, but i don't know how to parse it.

(Lol, seems like you're writing my addon.. :P (Yes, i will post it as soon as the basics are done))

Btw, got the tabs to show properly, but there's no text in them.. I'll get along to that later..

Thanks alot for the help so far!
  Reply With Quote
04-25-08, 06:16 PM   #10
Akryn
A Firelord
AddOn Author - Click to view addons
Join Date: Mar 2008
Posts: 479
Originally Posted by hipjipp View Post
I've read and understood the code, even shaped it up a notch, but since i'm still near the bottom of the lua society i have no idea on how to use the "OnTabClick(num)" code.. I know the point of it, but i don't know how to parse it.

(Lol, seems like you're writing my addon.. :P (Yes, i will post it as soon as the basics are done))

Btw, got the tabs to show properly, but there's no text in them.. I'll get along to that later..

Thanks alot for the help so far!
yeah the text won't show up because there's no fontstring for it to be in, you'll need to create one, oops :P

OnTabClick is just a function that you create. you don't have to use that name or even make a single function to handle tab clicks. the general idea is to use it to change the appearance of the active tab to active, dim all the other tabs, hide anything in the window that shouldn't be shown anymore, and show new stuff that is in the new active tab.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Table help


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