Menu Help

I’m trying to create a little inventory system and I’ve run into a problem with the menu. What I’m trying to do is create a menu where it loops through a table and creates a button on a DPanelList with the value from the table set as the Text for the button.

Problem:
The problem is that WeaponPanel isn’t being added to the DPaneList and it’s just being put in the corner of my screen. I’m also getting an error when I’m trying to set the text of the button to the value of the table.

[LUA]

local InventoryBackround = vgui.Create(“DFrame”)
InventoryBackround:SetSize( 300, 350 )
InventoryBackround:Center()
InventoryBackround:ShowCloseButton( true )
InventoryBackround:MakePopup()
InventoryBackround:SetTitle("")
InventoryBackround.Paint= function()
draw.RoundedBox( 0, 0, 0, InventoryBackround:GetWide(), InventoryBackround:GetTall(), Color( 52, 54, 59, 255 ) )
end

local InventoryForeGround = vgui.Create(“DFrame”)
InventoryForeGround:SetParent( InventoryBackround )
InventoryForeGround:SetSize( 290, 340 )
InventoryForeGround:SetPos( 5, 5 )
InventoryForeGround:SetTitle("")
InventoryForeGround.Paint= function()
draw.RoundedBox( 0, 0, 0, InventoryForeGround:GetWide(), InventoryForeGround:GetTall(), Color( 200, 200, 200, 255 ) )
end

local InventoryForeGroundBar = vgui.Create(“DFrame”)
InventoryForeGroundBar:SetParent( InventoryForeGround )
InventoryForeGroundBar:SetSize( 280, 35 )
InventoryForeGroundBar:SetPos( 5, 5 )
InventoryForeGroundBar:SetTitle("")
InventoryForeGroundBar:ShowCloseButton( false )
InventoryForeGroundBar.Paint= function()
draw.RoundedBox( 0, 0, 0, InventoryForeGround:GetWide(), InventoryForeGround:GetTall(), Color( 52, 54, 59, 255 ) )
end

local InventoryForeGroundMenu = vgui.Create(“DFrame”)
InventoryForeGroundMenu:SetParent( InventoryForeGround )
InventoryForeGroundMenu:SetSize( 280, 290 )
InventoryForeGroundMenu:SetPos( 5, 45 )
InventoryForeGroundMenu:SetTitle("")
InventoryForeGroundMenu:ShowCloseButton( false )
InventoryForeGroundMenu.Paint= function()
draw.RoundedBox( 0, 0, 0, InventoryForeGroundMenu:GetWide(), InventoryForeGroundMenu:GetTall(), Color( 52, 54, 59, 255 ) )
end

local InventoryCloseButton = vgui.Create(“DButton”)
InventoryCloseButton:SetParent( InventoryForeGround )
InventoryCloseButton:SetSize( 100, 25 )
InventoryCloseButton:SetPos( 100, 305 )
InventoryCloseButton:SetText(“Close”)
InventoryCloseButton.DoClick = function()
InventoryBackround:Close()
end

– Table testing

local Weapons = { }
local Gear = file.Read(“Inventory/” … LocalPlayer():FormatSteamID() … “.txt” )
local GearExploded = string.Explode( "
", Gear )
table.insert( Weapons, GearExploded )
PrintTable( Weapons, Items )

– Icons
local IconList = vgui.Create( “DPanelList” )
IconList:SetParent( InventoryForeGroundMenu )
IconList:EnableVerticalScrollbar( true )
IconList:EnableHorizontal( false )
IconList:SetPadding( 4 )
IconList:SetPos(5,30)
IconList:SetSize(260, 220)
IconList.Paint= function()
draw.RoundedBox( 0, 0, 0, IconList:GetWide(), IconList:GetTall(), Color( 200, 200, 200, 255 ) )
end

for k, v in pairs( Weapons ) do
local WeaponPanel = vgui.Create(“DPanel”)
WeaponPanel:SetSize( 250, 25 )

    local DButtonTesting = vgui.Create("DButton", WeaponPanel)
    DButtonTesting:SetSize( 250, 25 )
    DButtonTesting:SetText( v ) -- Erroring here: [@RunString:78] bad argument #1 to 'SetText' (string expected, got table)
    DButtonTesting:SetPos( 5, 5 )
    
end
IconList:AddItem( WeaponPanel )

–text
local InventoryText = vgui.Create(“DLabel”)
InventoryText:SetFont(“Trebuchet24” )
InventoryText:SetParent( InventoryBackround )
InventoryText:SetText(“Inventory”)
InventoryText:SetPos( 105, 15 )
InventoryText:SizeToContents()

local InventoryMenuText = vgui.Create(“DLabel”)
InventoryMenuText:SetFont(“Trebuchet24” )
InventoryMenuText:SetParent( InventoryForeGroundMenu )
InventoryMenuText:SetText(“Items”)
InventoryMenuText:SetPos( 5, 5 )
InventoryMenuText:SizeToContents()
[/LUA]

Heres my Console:
[LUA]
1:
1 = weapon_m4
2 = weapon_mp5
3 = weapon_tmp
4 = weapon_physcannon
5 = weapon_pumpshotgun
6 = gmod_tool
7 = weapon_para
8 = weapon_physgun
9 = weapon_physcannon
10 = weapon_physgun
11 = gmod_tool
12 = weapon_physcannon
13 = weapon_physgun
14 = gmod_tool
15 = weapon_physcannon
[@RunString:78] bad argument #1 to ‘SetText’ (string expected, got table)
[/LUA]

If you need me to clarify anything let me know please. Sometimes I have a hard time trying to explain things.

Well as far as the weaponpanel not adding, Pretty simple to see whats happening

[lua]for k, v in pairs( Weapons ) do
local WeaponPanel = vgui.Create(“DPanel”)
WeaponPanel:SetSize( 250, 25 )

local DButtonTesting = vgui.Create("DButton", WeaponPanel)
DButtonTesting:SetSize( 250, 25 )
DButtonTesting:SetText( v )
DButtonTesting:SetPos( 5, 5 )

end
IconList:AddItem( WeaponPanel )[/lua]

Your adding “WeaponPanel” Which doesnt exist, Try

[lua]for k, v in pairs( Weapons ) do
local WeaponPanel = vgui.Create(“DPanel”)
WeaponPanel:SetSize( 250, 25 )

local DButtonTesting = vgui.Create("DButton", WeaponPanel)
DButtonTesting:SetSize( 250, 25 )
DButtonTesting:SetText( v )
DButtonTesting:SetPos( 5, 5 )

IconList:AddItem( WeaponPanel )

end[/lua]

The error. Do something like [lua]DButtonTesting:SetText( tostring(v) )[/lua] For some reason its giving a table so lets find out what table this is

Ah thank you for the help with the first part. When I change it to tostring( v ) it prints the table number and not the value of the table.

[lua]if ( type( v ) == “table” ) then
PrintTable( v )
end[/lua]

Add something like this before the SetText, And see what table its printing.

Its printing the data in table:
[LUA]
1 = weapon_m4
2 = weapon_mp5
3 = weapon_tmp
4 = weapon_physcannon
5 = weapon_pumpshotgun
6 = gmod_tool
7 = weapon_para
8 = weapon_physgun
9 = weapon_physcannon
10 = weapon_physgun
11 = gmod_tool
12 = weapon_physcannon
13 = weapon_physgun
14 = gmod_tool
15 = weapon_physcannon
[/LUA]

-snip-

Read the code wrong, One second.

[lua]-- Table testing
*
local Weapons = { }
local Gear = file.Read(“Inventory/” … LocalPlayer():FormatSteamID() … “.txt” )
local GearExploded = string.Explode( "
", Gear )
table.insert( Weapons, GearExploded )
PrintTable( Weapons, Items )[/lua]

Do something like

[lua]-- Table testing
*
local Gear = file.Read(“Inventory/” … LocalPlayer():FormatSteamID() … “.txt” )
local Weapons = string.Explode( "
", Gear )
PrintTable( Weapons, Items )[/lua]

Thank man that works, but I don’t really quite understand what you did. Why does PrintTable work if Weapons is no longer a table?

[lua]table.insert( Weapons, GearExploded )[/lua]
Basically you were adding a table on to another one.

I never declared that GearExploded was a table though. Isn’t that adding the info contained in GearExploded to the table Weapons?

string.Explode turns a string in to a table.

Oh alright thanks for the info dude, really helped me out here! Instead of making a new thread I thought I might as well just ask here.

I’m trying to make an in-game report system. I’m trying to make it so you have to select a players name from a DComboBox first and then type in the DTextEntry. It works fine when I select a persons name and type something in the DTextEntry Box but when I don’t select a name it doesn’t print “You have to select a player from the list first!”.
[LUA]
local Report = vgui.Create(“DTextEntry” )
Report:SetParent( SheetItemThree )
Report:SetPos( 10, 400 )
Report:SetSize( 400, 20 )
Report.OnEnter = function()
if PlayerList:GetSelectedItems() and PlayerList:GetSelectedItems()[1]:GetValue() != nil then
LocalPlayer():ChatPrint(“We selected a name and typed something in the DTextEntry”)
else
LocalPlayer():ChatPrint(“You have to select a player from the list first!”) – attempt to index field ‘?’ (a nil value)

end

end
[/LUA]

Add a check to make it so if the textentry isnt “” then it will use the combobox.