Why is my DPanelList not working correctly.

No errors in particular tho.
Oh and, the first Icon is never shown.



-- definitions, rest of gui
	model_icons:SetPos(job_panel:GetWide()-64*4-4,1)
	model_icons:SetSize(258,job_panel:GetTall())
	model_icons:EnableHorizontal(true)
	model_icons:EnableVerticalScrollbar(true)
	model_icons:SetSpacing(10)
-- some loop code shizzle

				temp_spawn = vgui.Create("SpawnIcon",model_icons)
				temp_spawn:SetModel(v1) -- v1 is the value of the loop it's in
				temp_spawn:SetSize(64)
				model_icons:AddItem(temp_spawn)


PS: Nevermind the Ugliness, I still got work to do.

Get rid of the
[lua]temp_spawn:SetSize(64)[/lua]

and try

[lua]local temp_spawn = vgui.Create( “SpawnIcon” )[/lua]

not sure if the parenting is messing it up.
Tell us if anything changes.

I’m pretty sure you’re supposed to use SetIconSize( size )

i combined both of your solutions, none of them worked properly.
The Icon now cuts in half. I don’t know why

can you show us the exact code you’re using so we can test it?

It’s a gamemode.
I would have to leak the whole gamemode system for you to be able to test it.
I’m sure of the following facts:
-It’s not a problem of the loop
-Neither a problem of the gamemode (jobs etc) variables as well

Well, I can give you the whole menu



	local temp_label
	local frame = vgui.Create("DFrame")
	frame:SetTitle("Life Selection Menu")
	frame:SetDraggable(false)
	frame:SetSizable(false)
	frame:ShowCloseButton(false)
	frame:SetSize(700,500)
	frame:Center()
	frame:MakePopup()
	local w,h = frame:GetSize()
	local propsheet = vgui.Create("DPropertySheet",frame)
	propsheet:SetPos(5,25)
	propsheet:SetSize(w-10,h-25)
	local job_panel = vgui.Create("DPanel")
	job_panel:SetSize(propsheet:GetWide(),propsheet:GetTall()-5)
	propsheet:AddSheet("Character",job_panel)
	local job_jobicons = vgui.Create("DPanelList",job_panel)
	job_jobicons:SetSize(64,job_panel:GetTall())
	job_jobicons:SetPos(job_panel:GetWide()-64*5-6,1)
	local temp_spwn
	local model_icons = vgui.Create("DPanelList",job_panel)
	model_icons:SetPos(job_panel:GetWide()-64*4-4,1)
	model_icons:SetSize(258,job_panel:GetTall())
	model_icons:EnableVerticalScrollbar(true)
	model_icons:EnableHorizontal(true)
	
	for k,v in pairs(ToxicRP.Jobs) do
		temp_spawn = vgui.Create("SpawnIcon")
		temp_spawn:SetModel(ToxicRP.Jobs[k].Levels[0].ModelM[1])
		temp_spawn:SetToolTip(k)
		temp_spawn.DoClick = function()
			model_icons:Clear()

			for k1,v1 in pairs (ToxicRP.Jobs[k].Levels[0].ModelM) do
		
				temp_spawn = vgui.Create("SpawnIcon")
				temp_spawn:SetModel(v1)
				temp_spawn:SetToolTip(ToxicRP.Jobs[k].Levels[0].Name)
				temp_spawn:SetIconSize(64)
				model_icons:AddItem(temp_spawn)
	
			end
			
		end
		job_jobicons:AddItem(temp_spawn)
	end


Might be able to test it if you use the following code for a basic structure of the required tables



ToxicRP = {}
ToxicRP.Jobs = {}
ToxicRP.Jobs["name1"] = {["Levels"] = {[0]={["ModelM"]={"Enter a few models of your liking here"}}}}
ToxicRP.Jobs["name1"] = {["Levels"] = {[1]={["ModelM"]={"Enter a few models of your liking here"}}}}
ToxicRP.Jobs["name2"] = {["Levels"] = {[0]={["ModelM"]={"Enter a few models of your liking here"}}}}
ToxicRP.Jobs["name1"] = {["Levels"] = {[1]={["ModelM"]={"Enter a few models of your liking here"}}}}


(PS: I typed this in here, not sure for any errors)

EDIT: Tested something using lua_run_cl

The exact same problems occour if I make a DPanelList and EnableHorizontal and add spawn icons. da faq?

Since I can’t really test the script I can try pointing out some things you might want to try. First, you’re using temp_spawn as a identifier for 2 different sets of SpawnIcons. Second, I don’t know what set of SpawnIcons you want on what list, but change the fist set of SpawnIcons instead of temp_spawn, rename it temp_spawn1 then do
[lua]job_jobicons:AddItem(temp_spawn1)[/lua] down below.

I’m a little tired so if i’m hard to understand I’ll try re-explaining it.

Well a couple things I see that are incorrect.

  1. You should make the temp_spawn local to each for loop.
  2. You should make the second temp_spawn you create into temp_spawn1 or some other name
  3. You should do SetIconSize for both temp_spawn and temp_spawn1

@josh98 AND @SW

I tried all that without you people hinting me it. It failed

I also found this code that for some reason works



function fridge()
        local food = {}
 
        food[1] = "models/props_junk/garbage_milkcarton002a.mdl"
	food[2] = "models/props_junk/PopCan01a.mdl"
	food[3] = "models/props_junk/garbage_takeoutcarton001a.mdl"
	food[4] = "models/props_junk/watermelon01.mdl"
	food[5] = "models/props_junk/garbage_metalcan001a.mdl"
	food[6] = "models/props_lab/box01a.mdl"
	food[7] = "models/props_lab/box01b.mdl"
 
        local frame = vgui.Create("DFrame")
	local IconList = vgui.Create( "DPanelList", frame ) 
 
	frame:Center()
	frame:SetSize(220,200)
	frame:SetTitle("Fridge")
	frame:MakePopup()
 
 	IconList:EnableVerticalScrollbar( true ) 
 	IconList:EnableHorizontal( true ) 
 	IconList:SetPadding( 4 ) 
	IconList:SetPos(10,30)
	IconList:SetSize(200, 160)
 
	for k,v in pairs(food) do
	local icon = vgui.Create( "SpawnIcon", IconList ) 
	icon:SetModel( v )
 	IconList:AddItem( icon )
	icon.DoClick = function( icon ) surface.PlaySound( "ui/buttonclickrelease.wav" ) RunConsoleCommand("gm_spawn", v) end 
	end 	
end


So, what the fuck?

Try removing the model_icons:Clear() from your script, I created a DPanelList with SpawnIcons a while back with the same problem, and if I didn’t use the Clear() function, it had no problem @ all with the SpawnIcons.
Try to create a function that just re-creates the whole DPanelList instead (I can even help you with that if you want me to)

EDIT: This might work (haven’t tested it yet)



	local temp_label
	local frame = vgui.Create("DFrame")
	frame:SetTitle("Life Selection Menu")
	frame:SetDraggable(false)
	frame:SetSizable(false)
	frame:ShowCloseButton(false)
	frame:SetSize(700,500)
	frame:Center()
	frame:MakePopup()
	local w,h = frame:GetSize()
	local propsheet = vgui.Create("DPropertySheet",frame)
	propsheet:SetPos(5,25)
	propsheet:SetSize(w-10,h-25)
	local job_panel = vgui.Create("DPanel")
	job_panel:SetSize(propsheet:GetWide(),propsheet:GetTall()-5)
	propsheet:AddSheet("Character",job_panel)
	local job_jobicons = vgui.Create("DPanelList",job_panel)
	job_jobicons:SetSize(64,job_panel:GetTall())
	job_jobicons:SetPos(job_panel:GetWide()-64*5-6,1)
	local temp_spawn
	local model_icons = vgui.Create("DPanelList",job_panel)
	model_icons:SetPos(job_panel:GetWide()-64*4-4,1)
	model_icons:SetSize(258,job_panel:GetTall())
	model_icons:EnableVerticalScrollbar(true)
	model_icons:EnableHorizontal(true)
	
	
	local function ModelListRcrt()
		model_icons = vgui.Create("DPanelList",job_panel)
		model_icons:SetPos(job_panel:GetWide()-64*4-4,1)
		model_icons:SetSize(258,job_panel:GetTall())
		model_icons:EnableVerticalScrollbar(true)
		model_icons:EnableHorizontal(true)
		
		for k1,v1 in pairs (ToxicRP.Jobs[k].Levels[0].ModelM) do
			temp_spawn = vgui.Create("SpawnIcon")
			temp_spawn:SetModel(v1)
			temp_spawn:SetToolTip(ToxicRP.Jobs[k].Levels[0].Name)
			temp_spawn:SetIconSize(64)
			model_icons:AddItem(temp_spawn)
		end
	end
	
	for k,v in pairs(ToxicRP.Jobs) do
		temp_spawn = vgui.Create("SpawnIcon")
		temp_spawn:SetModel(ToxicRP.Jobs[k].Levels[0].ModelM[1])
		temp_spawn:SetToolTip(k)
		temp_spawn.DoClick = function()
			model_icons:Remove()
			ModelListRcrt()
		end
		job_jobicons:AddItem(temp_spawn)
	end


@ The Above
Doesnt change anything…
And I really am not new to LUA coding, except this issue is something I never encountered and I am unable to explain why.

Ahhh well, sorry but I wont be able to give anymore help, because when I had the same problem doing something similar to that fixed it.
And sorry if it seems that I think that you’re “unexperienced” or something, I’d just rather help you “too much” than not enough.

I got the menu to work, but I had to change your tables a little. I tested it, so tell me if this is what you needed.

[lua]ToxicRP = {}
ToxicRP.Jobs = {}
ToxicRP.Jobs[“Alyx”] = {Level = { 0 }, Models = { “models/player/alyx.mdl”, “models/player/barney.mdl”}}
ToxicRP.Jobs[“Breen”] = {Level = { 0 }, Models = { “models/player/breen.mdl”, “models/player/kleiner.mdl”}}

concommand.Add( “toxicrp_menu”, function()
local frame = vgui.Create(“DFrame”)
frame:SetTitle(“Life Selection Menu”)
frame:SetDraggable(false)
frame:SetSizable(false)
frame:ShowCloseButton(true)
frame:SetSize(700,500)
frame:Center()
frame:MakePopup()
local w,h = frame:GetSize()
local propsheet = vgui.Create(“DPropertySheet”,frame)
propsheet:SetPos(5,25)
propsheet:SetSize(w-10,h-25)
local job_panel = vgui.Create(“DPanel”)
job_panel:SetSize(propsheet:GetWide(),propsheet:GetTall()-5)
propsheet:AddSheet(“Character”,job_panel)
local job_jobicons = vgui.Create(“DPanelList”,job_panel)
job_jobicons:SetSize(64,job_panel:GetTall())
job_jobicons:SetPos(job_panel:GetWide()-645-6,1)
local model_icons = vgui.Create(“DPanelList”,job_panel)
model_icons:SetPos(job_panel:GetWide()-64
4-4,1)
model_icons:SetSize(258,job_panel:GetTall())
model_icons:EnableVerticalScrollbar(true)
model_icons:EnableHorizontal(true)

for k, v in pairs(ToxicRP.Jobs) do
	local temp_spawn = vgui.Create("SpawnIcon")
	temp_spawn:SetModel(v.Models[1])
	temp_spawn:SetToolTip(k)
	temp_spawn.DoClick = function()
		model_icons:Clear()
	end
	job_jobicons:AddItem(temp_spawn)
	for a, b in pairs( v.Models ) do
		local icon = vgui.Create( "SpawnIcon" )
		icon:SetModel( b )
		icon:SetToolTip( k );
		model_icons:AddItem( icon )
	end
end

end )[/lua]

Table isn’t in the correct structure at all, but oh well. can be fixed. Just please do tell me. What exactly was wrong?
PS: THis code isnt really what I wanted at all.
The job_jobicons DPanelList was a Panel List that was meant for when clicked displays the models

Bump

If job_jobicons was supposed to display the player models, what did you want temp_spawn to display?

No
job_jobicons Dispalys the factions
job_modelicons displays the models
temp_spawn is a temporary variable for creating the SpawnIcons once you press one of the job_jobicons