Anyone can explain me how to use dynamic Elements Panel with table loops ?

Hi everyone !
All is in the title, I have some problem to figure how to setup my table to fit in the loop below


 
 DLblThisOF2 = {}
table.insert( DLblThisOF2 , {OrderNum = "1", PosX = 7 , PosY 50  , Text = "Ents1 / OverAll", SetConvar = "sbox_godmode"}  )
table.insert( DLblThisOF2 , {OrderNum = "2", PosX = 7 , PosY 90  , Text = "Name", SetConvar = "sbox_godmode"}  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 7 , PosY 120 , Text = "Distance : ", SetConvar = "sbox_godmode"}  )


	--  v.Text[1]
		
 for k, v in pairs( DLblThisOF2 ) do

for i = 1, 3 do

local DChkbxNameHud = vgui.Create( "DCheckBoxLabel" ) // Create the checkbox
DChkbxNameHud:SetParent( DPanel )
DChkbxNameHud:SetPos( v.PosX, v.PosY )                        // Set the position
DChkbxNameHud:SetText( v.Text )                   // Set the text next to the box
DChkbxNameHud:SetConVar( "sbox_godmode" )             // Change a ConVar when the box it ticked/unticked
DChkbxNameHud:SetValue( 0 )             // Initial value ( will determine whether the box is ticked too )
DChkbxNameHud:SizeToContents()                      // Make its size the same as the contents
DChkbxNameHud:SetDark( true )

end
end



anyone with better way ?

Also I got this following error -->

Thanks in advance !

[LUA]
table.insert( DLblThisOF2 , {OrderNum = “1”, PosX = 7 , PosY 50 , Text = “Ents1 / OverAll”, SetConvar = “sbox_godmode”} )
table.insert( DLblThisOF2 , {OrderNum = “2”, PosX = 7 , PosY 90 , Text = “Name”, SetConvar = “sbox_godmode”} )
table.insert( DLblThisOF2 , {OrderNum = “3”, PosX = 7 , PosY 120 , Text = "Distance : ", SetConvar = “sbox_godmode”} )
[/LUA]

You’re just doing
[LUA]
, PosY 50 ,
[/LUA]

You forgot the = :v:

That error is because you left out the =s after the PosY in your tables. And not it’s necessary to have 2 nested for loops there… you will triple create everything

edit: fuck, ninja’d

Oops many thanks :smiley:

it is possible my loops, loops too many times with


 for k, v in pairs( DLblThisOF2 ) do

for i = 1, 3 do

?

because I see the text a little bit blurred !

edit :

Oh I see better now many thanks to both,

I removed the :


for i = 1, 3 do 
 -- code ...

end


and all things work well now :smiley:

Thanks again !

you don’t need the numeric for loop

I have another problem in this.

I have to get custom convar and when I run it the console say to me


 
local HudIEEName = CreateClientConVar( "HudIEEName", "0", true, true ) 
local HudIEEHealth = CreateClientConVar( "HudIEEHealth", "0", true, true ) 
local HudIEEMapModel = CreateClientConVar( "HudIEEMapModel", "0", true, true ) 
local HudIEEIsWorld = CreateClientConVar( "HudIEEIsWorld", "0", true, true ) 
local HudIEEDistance = CreateClientConVar( "HudIEEDistance", "0", true, true )



 DLblThisOF2 = {}
table.insert( DLblThisOF2 , {OrderNum = "1", PosX = 5 , PosY = 55 + 5  , Text = "Ents1 / OverAll", SetConvar = "sbox_godmode", GetConvar =  "sbox_godmode"  }  )
table.insert( DLblThisOF2 , {OrderNum = "2", PosX = 5 , PosY = 75 + 5 , Text = "Name", SetConvar = "HudIEEName",  GetConvar =  "HudIEEName:" .. "GetInt()" }  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 95 + 5 , Text = "Health", SetConvar = "HudIEEHealth",  GetConvar =  "HudIEEHealth:" .. "GetInt()" }  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 115 + 5 , Text = "Model / Map Name", SetConvar = "HudIEEMapModel",  GetConvar = "HudIEEMapModel:" .. "GetInt()"}  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 135 + 5 , Text = "IsWorld ?", SetConvar = "HudIEEIsWorld",  GetConvar = "HudIEEIsWorld:" .. "GetInt()"}  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 155 + 5 , Text = "Distance", SetConvar = "HudIEEDistance",  GetConvar = "HudIEEDistance:" .. "GetInt()"}  )


for k, v in pairs( DLblThisOF2 ) do
local DChkbxNameHud = vgui.Create( "DCheckBoxLabel" ) 
DChkbxNameHud:SetParent( DPanel )
DChkbxNameHud:SetPos( v.PosX, v.PosY )                    
DChkbxNameHud:SetText( v.Text )                
DChkbxNameHud:SetConVar(  v.GetConvar   )   --          <-- Here is the problem

DChkbxNameHud:SizeToContents()  
DChkbxNameHud:SetDark( true )

end



Thanks in advance again !

Edit: Oh and how to have on ConVar ?

Not sure what you’re trying to do there with the setconvar/getconvar thing… but you should just put the name of the convar in there. The checkbox will set that convar to 0 or 1. Something like this should work:


local HudIEEName = CreateClientConVar( "HudIEEName", "0", true, true ) 
local HudIEEHealth = CreateClientConVar( "HudIEEHealth", "0", true, true ) 
local HudIEEMapModel = CreateClientConVar( "HudIEEMapModel", "0", true, true ) 
local HudIEEIsWorld = CreateClientConVar( "HudIEEIsWorld", "0", true, true ) 
local HudIEEDistance = CreateClientConVar( "HudIEEDistance", "0", true, true )



 DLblThisOF2 = {}
table.insert( DLblThisOF2 , {OrderNum = "1", PosX = 5 , PosY = 55 + 5  , Text = "Ents1 / OverAll", ConVar = "sbox_godmode" }  )
table.insert( DLblThisOF2 , {OrderNum = "2", PosX = 5 , PosY = 75 + 5 , Text = "Name", ConVar = "HudIEEName" }  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 95 + 5 , Text = "Health", ConVar = "HudIEEHealth" }  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 115 + 5 , Text = "Model / Map Name", ConVar = "HudIEEMapModel" }  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 135 + 5 , Text = "IsWorld ?", ConVar = "HudIEEIsWorld" }  )
table.insert( DLblThisOF2 , {OrderNum = "3", PosX = 5 , PosY = 155 + 5 , Text = "Distance", ConVar = "HudIEEDistance" }  )


for k, v in pairs( DLblThisOF2 ) do
local DChkbxNameHud = vgui.Create( "DCheckBoxLabel" ) 
DChkbxNameHud:SetParent( DPanel )
DChkbxNameHud:SetPos( v.PosX, v.PosY )                    
DChkbxNameHud:SetText( v.Text )                
DChkbxNameHud:SetConVar( v.ConVar )

DChkbxNameHud:SizeToContents()  
DChkbxNameHud:SetDark( true )

end

As for the notification thing I think that’s when you create a cvar with the FCVAR_NOTIFY flag and I’m not sure if it works on client cvars.

It’s telling you right here:

The command ‘HudIEEName:GetInt()’ has invalid characters, the characters being :

Why are you doing
[lua]GetConvar = “HudIEEName:” … “GetInt()”[/lua]
which is exactly the same as
[lua]GetConvar = “HudIEEName:GetInt()”[/lua]

it should just be
[lua]GetConvar = “HudIEEName”[/lua]

EDIT: Ninja’d :suicide:

Ouch damn it work :smiley:
I’m mean just with the

thanks again :smiley:

Hello again :smiley:

I have other troubles with writing table to a DLabel , when I open my Frame I got this weird text,
is there a way to print it on a better reading ?

The other code parts is below on the first post for reference.




local DPanelAA = vgui.Create( "DPanel", DPanelA )
DPanelAA:SetPos( 10, 260 ) -- Set the position of the panel
DPanelAA:SetSize( 270, 120 ) -- Set the size of the panel

   
DPanelAA.Paint = function(me)
	draw.RoundedBox( 0, 0, 0, me:GetWide(), me:GetTall(), Color( 150, 150,150, 205  ) )
	surface.SetDrawColor( Color(36,43,61, 255) )
	surface.DrawOutlinedRect( 0, 0, me:GetWide(), me:GetTall() )
end



local DLblA6 = vgui.Create( "DLabel", DPanelAA )
DLblA6:SetPos( 10, 10 )
DLblA6:SetSize( 150, 100 )
DLblA6:SetText( table.ToString( DLblThisOF2 , This , true ) ) --  Set the text of the label
-- DLblA6:SizeToContents() -- Size the label to fit the text in it
DLblA6:SetDark( 1 ) -- Set the colour of the text inside the label to a darker one
DLblA6:SetFont("defaultbold")



http://s28.postimg.org/5oo7qvep9/Weird_Table_Gmod.gif

Edit 2 : NeverMind I changed this to a DTextEntry and set to multiline enabled and set editable to false…

any one have a better idea ?