Entoros, don’t overcomplicate it for him by not commenting on what you do.
Ok, basically, your ‘Buttons’ table is full of sub-tables that have two values in them. I’m guessing that you want the first value to be the variable name. You can’t/don’t need to do that unless you want the buttons to be global variables.
If you want to keep track of your buttons, you need to create a separate table to store the buttons in. Then you loop through the info table, create the buttons and store the actual button objects in a separate table.
Here’s how it works…
[lua]
– button info
local button_info =
{
-- this way is the same as..
-- button_info[ 1 ] = { ... }
-- button_info[ 2 ] = ...
-- this table has the index of one
{ "Title1", { 50, 50 } },
-- the first value( Title2 ) has the index
-- of 1 and the second value( the table )
-- has the index of 2
-- this table has the index of two
{ "Title2", { 50, 150 } }
--[[
button_info = { };
button_info[ 1 ] =
{
[ 1 ] = "Title2",
[ 2 ] =
{
[ 1 ] = 50,
[ 2 ] = 150
}
}
]]
};
– table that keeps the actual buttons
local actual_buttons = { };
function CreateButtons( )
-- loop through the info table
-- i is the current index( 1, 2, ... )
-- info is the table with that index
for i, info in pairs( button_info ) do
-- create a new button( it can be local here )
-- you can also do 'actual_buttons[ i ] = ... '
-- but then every line would get a little longer
-- since you'd have to replace 'button' with that
-- code
local button = vgui.Create( "DButton", parent );
-- set the button's text to the first value
-- we get from the loop
button:SetText( info[ 1 ] );
-- set the pos to the first and second values
-- we have in the second value we get from the
-- loop
-- 'info[ 2 ]' is the table after the title
-- 'info[ 2 ][ 1 ]' is the first value in that table
button:SetPos( info[ 2 ][ 1 ], info[ 2 ][ 2 ] );
-- and finally store the button in your button table
actual_buttons[ i ] = button;
end
end
[/lua]