LUA'ing for derma, keep getting 'table was expected, got string...'

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:

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”)

			for a,b,c,d,e in ipairs(TList) do
				Msg("Added line to table with strings ", a, b, c, d, e)


TButton.SetText(“Get Teams?”)


TButton:SetText(“Get Teams?”)

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.

(This will be slower on slower pc’s).

Thank you, apparently I wasn’t clicking the button fast enough :stuck_out_tongue:

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.

self.Teampanel = vgui.Create(“DPanelList”)
self.Teampanel:SetSize((self.ToolPanel:GetWide() - 10), self.ToolPanel:GetTall())
self.Teampanel.Paint = function()
surface.SetDrawColor(170, 170, 170, 255)
– 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)
TButton = vgui.Create(“DButton”, self.Teampanel)
TButton:SetPos(7, 7)
TButton.DoClick = function()
MBO = DermaMenu() – Menu Button Options, is a menu
MBO:AddOption(“Load/Reload Teams List”, function()
drawteamgraph() 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")
				for a,b,c,d in pairs (TList) do


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 :wink:

So, tell me what happens when you parent a DListView to a DermaMenu. What does it look like?

Whoa… I actually meant to put that in my InfoPanel or w/e, thanks for pointing that out :stuck_out_tongue:

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.



really? How confusing :stuck_out_tongue:

Well, this time the menu appeared from the middle of the button. Doesn’t look as nice, but works anyways :slight_smile:


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.

Ok, will do. Now, I’m trying to get a DermaTable to fill with team data, so if you could take a look at my updated post #1, that would be great.

Basically what happens is the first column fills correctly with the team ID, but then the second column fills with this hexadecimal code.

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)

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)

 teamColToStr = string.Implode(", ", tempTeamCol)

 TListView:AddLine(k, v.Name, teamColToStr, v.Joinable, v.Score)


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…

Good luck.

Ya, I guess that’s the conclusion reached in the #lua chat room. I think you should hang out there, things get done faster :stuck_out_tongue:

Where is that?

oh, #luahelp