Hi there everyone, to give you a little background info, I know LUA in general, just not the way it’s done in gmod. Anyways, I’m just going to use this first post as my pasting error for a block of lua code I’m having trouble on. If you could scroll (or click) to the end of this thread and help, that would be awesome.
Here’s my block of code:
[lua]
function drawteamgraph()
local TList = team.GetAllTeams()
local TListView = vgui.Create(“DListView”, InfoPanel)
TListView:SetPos(15, 15)
TListView:SetSize(InfoPanel:GetWide()-25, InfoPanel:GetTall()-30)
TListView:AddColumn(“Team ID”)
TListView:AddColumn(“Team Name”)
TListView:AddColumn(“Color”)
TListView:AddColumn(“Joinable?”)
TListView:AddColumn(“Score”)
for a,b,c,d,e in ipairs(TList) do
TListView:AddLine(a,b,c,d,e)
Msg("Added line to table with strings ", a, b, c, d, e)
end
end
Ahh, thank you. I’m still getting used to the difference between : and ., even though it is a difference between child and property. Anyways, you wouldn’t happen to know why I just can’t click on the button?
Might be because you seem to be making a buttn every ‘Paint’. You should put the button creation outside of Paint. Paint is only meant to draw stuff, not create other vgui elements in it.
Paint gets called about 60 timer per second, meaning it creates 60 buttons per second in your code.
Thank you, apparently I wasn’t clicking the button fast enough
EDIT: Now, for some reason,the menu looks completely glitched up. The button shows up fine, but after adding some stuff, everything is messed up.
[lua]
self.Teampanel = vgui.Create(“DPanelList”)
self.Teampanel:SetSize((self.ToolPanel:GetWide() - 10), self.ToolPanel:GetTall())
self.Teampanel:SetPos(0,0)
self.Teampanel.Paint = function()
surface.SetDrawColor(170, 170, 170, 255)
end
– Take a moment to form the info panel
local InfoPanel = vgui.Create(“DPanel”, self.Teampanel)
InfoPanel:SetPos(30, 5)
InfoPanel:SetSize(self.Teampanel:GetWide() - 10, self.Teampanel:GetTall() -10)
–kthxbai!
TButton = vgui.Create(“DButton”, self.Teampanel)
TButton:SetPos(7, 7)
TButton:SetText(“Menu”)
TButton.DoClick = function()
MBO = DermaMenu() – Menu Button Options, is a menu
MBO:AddOption(“Load/Reload Teams List”, function()
drawteamgraph() end )
end
end
function drawteamgraph()
local TList = team.GetAllTeams()
local TListView = vgui.Create("DListView", MBO)
TListView:SetPos(MBO:GetWide()*.5, MBO:GetTall()*.5)
TListView:AddColumn("Team ID")
TListView:AddColumn("Team Name")
TListView:AddColumn("Color")
TListView:AddColumn("Joinable?")
TListView:AddColumn("Score")
for a,b,c,d in pairs (TList) do
TListView:AddLine(a,b,c,d)
end
Do you mind if I ask why you’re using self on TeamPanel? If this is just going in a clientside file, you don’t need to use self.Teampanel. But anyways, if I am correct and DermaMenu is the thing that’s like a right-click menu, then I don’t think you can make a DListView inside a DermaMenu.
Also, you added an ‘end’ for the function drawteamgraph, but not for the ‘for’ loop, as in ‘for a,b,c,d in pairs, etc.’. This would definitely screw your code.
Ya, it was the missing end that screwed me over. This is the derma panel for Flood, and I don’t really feel like editing out 50 self’s if I don’t need to
Whoa… I actually meant to put that in my InfoPanel or w/e, thanks for pointing that out
So pretty much, that didn’t work. Who knows, it might. I have a feeling it’s impossible, since I bet it gets cleared when the menu closes.
EDIT: And do you know how I can get the menu to appear below the button, rather than in the top left of my computer screen?
EDIT2: You can check my first post for an updated block of code.
Actually, it should appear from the position of the mouse. I don’t know if you can use SetPos() on DermaMenu’s, but you could just do MBO:SetPos(postion x, position y) if you could. Try it.
That’s a location in memory for a table (I think). That’s because TList has only two keys or whatever, a and b in your case, one is the number of the team, and the other is a table.
To do what you want, I think you would do this:
[lua]for k,v in pairs(TList) do
TListView:AddLine(k, v.Name, v.Color, v.Joinable, v.Score)
end[/lua]
Also note, the color will be the RGB values of the color.
This is not tested.
EDIT: Actually, the color is a table too (d’oh). I’ll see how to get the numbers out of it. Apparently tostring() don’t work on colours.
EDIT: Ok this is how I would do it:
[lua]for k,v in pairs(TList) do
tempTeamCol = {}
for k,v in pairs(v.Color) do
table.insert(tempTeamCol, v)
end
But there may be a better way. And that’s if you really want the R,G,B values of a team that bad. Since people aren’t going to be able to tell the colour intuitively by the RGB, I would just leave that out, take out the “Colour” column of your DListView, and use the first code in this post, but edit out the v.Color from the Addline. None of this is tested by the way…