table to DButton for a shop.

So I am trying to make a food shop and I think I am throwing myself in the deep end for myself personally as I am not the best with lua.

I am unsure of how I make a DButton correspond with a table of models, descriptions/whatever else and get that onto the buttons.

The items I am using are entities so I would I also need to put the entity name in the table too?

Here is the code that I have atm…
[lua]
function npcMenuFood()

local frame = vgui.Create("DFrame")
frame:SetSize(900,750)
frame:Center()
frame:SetVisible(true)
frame:MakePopup()
frame:SetDraggable(false)
frame:SetTitle("Food Shop")

local scroll = vgui.Create( "DScrollPanel",frame)
scroll:SetSize( 35, 720 )
scroll:SetPos( 430,25 )--860,25
scroll:Dock(FILL)

for i = 0, 12, 1 do
	local l = vgui.Create( "DButton",scroll)
	l:Dock( TOP )
	l:DockMargin( 0, 0, 0, 0 )
	l:SetSize(440,100)
end

local ModelTbl = {
{Model = "models/foodnhouseholditems/chipsdoritos.mdl", Desc = "Doritos"},
{Model = "models/foodnhouseholditems/mcdmeal2.mdl", Desc = "McDonalds Meal"},
{Model = "models/foodnhouseholditems/cakeslice2.mdl", Desc = "Slice of Cake"},
{Model = "models/foodnhouseholditems/apple2.mdl", Desc = "Apple"}
}

for k,v in ipairs(ModelTbl) do
    print(v.Model, v.Desc)
end

end
[/lua]

Like this for example?
[lua]
for k,v in pairs(ModelTbl) do
local ItemPanel = vgui.Create(“DPanel”, scroll)
ItemPanel:Dock(TOP)
ItemPanel:DockMargin(0, 5, 0, 0)
ItemPanel:SetSize(60, 60)

local ModelPanel = vgui.Create("DModel", ItemPanel)
ModelPanel:Dock(LEFT)
ModelPanel:SetSize(64, 64)
ModelPanel:SetModel(v.Model)

local ButtonPanel = vgui.Create("DButton", ItemPanel)
ButtonPanel:Dock(RIGHT)
ButtonPanel:DockMargin(0,10,0,10)
ButtonPanel:SetSize(60,60)
ButtonPanel:SetText(v.Desc)
ButtonPanel:SetColor(color_white)

end
[/lua]

Yes, that’s definitely a great help as it now looks like this

I am going to attempt to change the model positions as well as the button sizing etc.

Thanks very much for your help!

EDIT, I also had to change the model to DModelPanel as it’s not DModel. Just letting you know in case anyone else wanted to know who is reading this.

Oops yeah, that was my bad :v. And, for best results I’d just mess around with

Panel:DockMargin instead of :SetPos

Okay, thanks once again for the help :smiley:

[editline]26th September 2016[/editline]

Also if anyone could help me out with model positioning as I am struggling with it.

[lua]
function npcMenuFood()

local frame = vgui.Create("DFrame")
frame:SetSize(900,750)
frame:Center()
frame:SetVisible(true)
frame:MakePopup()
frame:SetDraggable(false)
frame:SetTitle("Food Shop")
function frame.Paint(s,w,h)

	draw.RoundedBox(0,0,0,w,h,Color(0,0,0,200))
	draw.RoundedBox(0,5,5,w - 10,h - 10,Color(10,10,10,100))

end

local scroll = vgui.Create( "DScrollPanel",frame)
scroll:SetSize( 35, 720 )
scroll:SetPos( 430,25 )--860,25
scroll:Dock(FILL)

local ModelTbl = {
{Model = "models/foodnhouseholditems/chipsdoritos.mdl", Desc = "Doritos", Money = "$59"},
{Model = "models/foodnhouseholditems/mcdmeal2.mdl", Desc = "McDonalds Meal", Money = "$120"},
{Model = "models/foodnhouseholditems/cakeslice2.mdl", Desc = "Slice of Cake", Money = "$43"},
{Model = "models/foodnhouseholditems/apple2.mdl", Desc = "Apple", Money = "$51"},
}

for k,v in pairs(ModelTbl) do
	local ItemPanel = vgui.Create("DButton", scroll)
	ItemPanel:Dock(TOP)
	ItemPanel:DockMargin(0, 5, 0, 0)
	ItemPanel:SetSize(60, 60)
	ItemPanel:SetText(v.Desc)
	ItemPanel:SetFont("bebas30")
	
	local ModelPanel = vgui.Create("DModelPanel", ItemPanel)
	ModelPanel:Dock(LEFT)
	ModelPanel:SetSize(64, 64)
	ModelPanel:SetModel(v.Model)
	ModelPanel:SetCamPos(Vector(1,4,-1))
	function ModelPanel:LayoutEntity( Entity ) return end
	
	local ButtonPanel = vgui.Create("DButton", ItemPanel)
	ButtonPanel:Dock(RIGHT)
	ButtonPanel:DockMargin(0,10,10,10)
	ButtonPanel:SetSize(60,60)
	ButtonPanel:SetText(v.Money)
end

end
[/lua]