• Need Big Time Help Finding Error in Code
    4 replies, posted
I am trying to program a column in the scoreboard for Gmod TTT that displays rank and rank color of the person. I am also trying to program, so the name colors of admins, owners, etc. have there steam name change color as well. I thought I was done, but when I launched Gmod I don't get a scoreboard and I get an error. Anybody know where the problem is or a working piece of code to get the rank column and changed name color? Changes to the code I made are labeled. The labels state where the change starts and stops with three enters above the start and three enters below the end. Error Log: [CODE]Warning: vgui.Create failed to create the VGUI component (TTTScorePlayerRow) [ERROR] gamemodes/terrortown/gamemode/vgui/sb_team.lua:98: attempt to index local 'row' (a nil value) 1. AddPlayerRow - gamemodes/terrortown/gamemode/vgui/sb_team.lua:98 2. UpdateScoreboard - gamemodes/terrortown/gamemode/vgui/sb_main.lua:278 3. Init - gamemodes/terrortown/gamemode/vgui/sb_main.lua:134 4. Create - lua/includes/extensions/client/panel/scriptedpanels.lua:153 5. ScoreboardCreate - gamemodes/terrortown/gamemode/cl_scoreboard.lua:27 6. unknown - gamemodes/terrortown/gamemode/cl_scoreboard.lua:34[/CODE] sb_row.lua [CODE]---- Scoreboard player score row, based on sandbox version include("sb_info.lua") local GetTranslation = LANG.GetTranslation local GetPTranslation = LANG.GetParamTranslation SB_ROW_HEIGHT = 24 --16 local PANEL = {} function PANEL:Init() -- cannot create info card until player state is known self.info = nil self.open = false self.cols = {} self:AddColumn( GetTranslation("sb_ping"), function(ply) return ply:Ping() end ) self:AddColumn( GetTranslation("sb_deaths"), function(ply) return ply:Deaths() end ) self:AddColumn( GetTranslation("sb_score"), function(ply) return ply:Frags() end ) if KARMA.IsEnabled() then self:AddColumn( GetTranslation("sb_karma"), function(ply) return math.Round(ply:GetBaseKarma()) end ) end -- Let hooks add their custom columns hook.Call("TTTScoreboardColumns", nil, self) for _, c in ipairs(self.cols) do c:SetMouseInputEnabled(false) end self.tag = vgui.Create("DLabel", self) self.tag:SetText("") self.tag:SetMouseInputEnabled(false) self.sresult = vgui.Create("DImage", self) self.sresult:SetSize(16,16) self.sresult:SetMouseInputEnabled(false) self.avatar = vgui.Create( "AvatarImage", self ) self.avatar:SetSize(SB_ROW_HEIGHT, SB_ROW_HEIGHT) self.avatar:SetMouseInputEnabled(false) self.nick = vgui.Create("DLabel", self) self.nick:SetMouseInputEnabled(false) self.voice = vgui.Create("DImageButton", self) self.voice:SetSize(16,16) self:SetCursor( "hand" ) end function PANEL:AddColumn( label, func, width ) local lbl = vgui.Create( "DLabel", self ) lbl.GetPlayerText = func lbl.IsHeading = false lbl.Width = width or 50 -- Retain compatibility with existing code table.insert( self.cols, lbl ) return lbl end --------Change Starts Here-------- local namecolor = { default = COLOR_WHITE, rank = Color(r, g, b, a), glow = math.abs(math.sin(CurTime() * 2) * 255) coder = Color(186, 0, 237, 93), superadmin = Color(14, 232, 232, 91), admin = Color(242, 178, 39, 95), mod = Color(94, 232, 81, 91) }; function GM:TTTScoreboardColorForPlayer(ply) if not IsValid(ply) then return namecolor.default end if ply:IsUserGroup("owner") then return Color(glow,glow,glow) elseif ply:IsUserGroup("coder") and GetGlobalBool("ttt_highlight_admins", true) then return namecolor.coder elseif ply:IsUserGroup("superadmin") and GetGlobalBool("ttt_highlight_admins", true) then return namecolor.superadmin elseif ply:IsUserGroup("admin") and GetGlobalBool("ttt_highlight_admins", true) then return namecolor.admin elseif ply:IsUserGroup("mod") and GetGlobalBool("ttt_highlight_admins", true) then return namecolor.mod end return namecolor.default end --------Change Ends Here-------- local function ColorForPlayer(ply) if IsValid(ply) then local c = hook.Call("TTTScoreboardColorForPlayer", GAMEMODE, ply) -- verify that we got a proper color if c and type(c) == "table" and c.r and c.b and c.g and c.a then return c else ErrorNoHalt("TTTScoreboardColorForPlayer hook returned something that isn't a color!\n") end end return namecolor.default end function PANEL:Paint() if not IsValid(self.Player) then return end -- if ( self.Player:GetFriendStatus() == "friend" ) then -- color = Color( 236, 181, 113, 255 ) -- end local ply = self.Player if ply:IsTraitor() then surface.SetDrawColor(255, 0, 0, 30) surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT) elseif ply:IsDetective() then surface.SetDrawColor(0, 0, 255, 30) surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT) end if ply == LocalPlayer() then surface.SetDrawColor( 200, 200, 200, math.Clamp(math.sin(RealTime() * 2) * 50, 0, 100)) surface.DrawRect(0, 0, self:GetWide(), SB_ROW_HEIGHT ) end return true end function PANEL:SetPlayer(ply) self.Player = ply self.avatar:SetPlayer(ply) if not self.info then local g = ScoreGroup(ply) if g == GROUP_TERROR and ply != LocalPlayer() then self.info = vgui.Create("TTTScorePlayerInfoTags", self) self.info:SetPlayer(ply) self:InvalidateLayout() elseif g == GROUP_FOUND or g == GROUP_NOTFOUND then self.info = vgui.Create("TTTScorePlayerInfoSearch", self) self.info:SetPlayer(ply) self:InvalidateLayout() end else self.info:SetPlayer(ply) self:InvalidateLayout() end self.voice.DoClick = function() if IsValid(ply) and ply != LocalPlayer() then ply:SetMuted(not ply:IsMuted()) end end self:UpdatePlayerData() end function PANEL:GetPlayer() return self.Player end function PANEL:UpdatePlayerData() if not IsValid(self.Player) then return end local ply = self.Player for i=1,#self.cols do -- Set text from function, passing the label along so stuff like text -- color can be changed self.cols[i]:SetText( self.cols[i].GetPlayerText(ply, self.cols[i]) ) end self.nick:SetText(ply:Nick()) self.nick:SizeToContents() self.nick:SetTextColor(ColorForPlayer(ply)) --------Change Starts Here-------- if ply:IsUserGroup("owner") then Self.cols[5]:SetText("Owner") Self.cols[5]:SetTextColor(glow,glow,glow) elseif ply:IsUserGroup("coder") then Self.cols[5]:SetText("Coder") Self.cols[5]:SetTextColor(namecolor.coder) elseif ply:IsUserGroup("superadmin") then Self.cols[5]:SetText("Super Admin") Self.cols[5]:SetTextColor(namecolor.superadmin) elseif ply:IsUserGroup("admin") then Self.cols[5]:SetText("Admin") Self.cols[5]:SetTextColor(namecolor.admin) elseif ply:IsUserGroup("mod") then Self.cols[5]:SetText("Moderator") Self.cols[5]:SetTextColor(namecolor.mod) end --------Change Ends Here-------- local ptag = ply.sb_tag if ScoreGroup(ply) != GROUP_TERROR then ptag = nil end self.tag:SetText(ptag and GetTranslation(ptag.txt) or "") self.tag:SetTextColor(ptag and ptag.color or COLOR_WHITE) self.sresult:SetVisible(ply.search_result != nil) -- more blue if a detective searched them if ply.search_result and (LocalPlayer():IsDetective() or (not ply.search_result.show)) then self.sresult:SetImageColor(Color(200, 200, 255)) end -- cols are likely to need re-centering self:LayoutColumns() if self.info then self.info:UpdatePlayerData() end if self.Player != LocalPlayer() then local muted = self.Player:IsMuted() self.voice:SetImage(muted and "icon16
All those errors are saying that the word "row" is not defined as anything, so any time that's it's used, it's nil (empty).
.
I'm not sure if this is a case of your not understanding the error message or what... but what the error you're getting means is that the vgui class you're trying to create doesn't exist. When that happens vgui.Create returns nil so any code tyring to use that element will error. Check for errors preventing sb_row from loading properly and post those.
[QUOTE=huntingrifle;47344156]All those errors are saying that the word "row" is not defined as anything, so any time that's it's used, it's nil (empty).[/QUOTE] How could I fix this though?
Sorry, you need to Log In to post a reply to this thread.