• Create DButtons from a table.
    10 replies, posted
Hi. I'm trying to make it easier to add buttons to my panel, so I decided to make a table. Now I'm trying to loop over it and make a new button each time. Here's my code. [code] local tab = tab or {} tab.button1 = { name = "Text", } tab.button2 = { name = "other text", } local drawSpot = 0 for k,v in pairs(tab) do drawSpot = drawSpot + 100 local button = vgui.Create("DButton", "panelx") button:SetPos(10,drawSpot) button:SetSize(50,50) button:SetText(tab[k].name) button.DoClick = function() --do whatever end end [/code] Yet this only makes 1 button. Any help?
How does it look like - show screenshot of entire screen.
[IMG]http://puu.sh/m7o9n/67c80491a8.png[/IMG] Colt M4-A1 is the name of the second and final table item.
You have to put each button in the tab table I believe. [code] local tab = { button1 = { name = "text" }, button2 = { name = "other text" } } [/code]
[QUOTE=Nick78111;49382896]You have to put each button in the tab table I believe. [code] local tab = { button1 = { name = "text" }, button2 = { name = "other text" } } [/code][/QUOTE] That doesn't change a thing.
[QUOTE=Netheous;49382902]That doesn't change a thing.[/QUOTE] Well this is how I did it in one of my addons, no need to be an a**
[QUOTE=Nick78111;49382955]Well this is how I did it in one of my addons, no need to be an a**[/QUOTE] Being an ass for pointing out that it doesn't change a thing? Oh boy.
[QUOTE=Nick78111;49382896]You have to put each button in the tab table I believe. [code] local tab = { button1 = { name = "text" }, button2 = { name = "other text" } } [/code][/QUOTE] That wouldn't change anything. It's just a different way of writing the exact same thing.
Just trying to help, but facepunch is so damn toxic. Now I remember why I never get on here.
[QUOTE=Nick78111;49382972]Just trying to help, but facepunch is so damn toxic. Now I remember why I never get on here.[/QUOTE] You are the one looking for a reason to call FP toxic lol. Also - your code seems to work fine for me. [img]http://puu.sh/m7q9g/970d7c0f5f.jpg[/img]
[QUOTE=Netheous;49383010]You are the one looking for a reason to call FP toxic lol. Also - your code seems to work fine for me. [img]http://puu.sh/m7q9g/970d7c0f5f.jpg[/img][/QUOTE] Weird. I probably did something wrong. Thanks for the help, merry christmas.
Sorry, you need to Log In to post a reply to this thread.