• DTextEntry:SetText not working? Possibly because of net error?
    4 replies, posted
Okay, I try not to clutter the forums with dumb questions but this one truly is stumping me. So my last resort is to outsource and ask the community. Little run down... I'm making a death-menu, which essentially makes you click "Respawn" every time you die, it also has a button for "Log". So, for the log button, I'm wanting to display DTextBoxes (CGTextBoxes [my custom designed element]) which all have values like the below: [code] LocalPlayer():Nick() LocalPlayer():SteamID() [/code] Now here's my problem... I'm trying to get my CGTextEntry to show the killer (attacker) via a: [code]net.Receive()[/code] but I get the following error when I do so... [code][ERROR] addons/cogent/lua/autorun/client/cl_death_popup.lua:154: Tried to use invalid object (type Panel) (Object was NULL or not of the right type) 1. SetText - [C]:-1 2. func - addons/cogent/lua/autorun/client/cl_death_popup.lua:154 3. unknown - lua/includes/extensions/net.lua:32 [/code] So here's the file locations and code in those files that pertain to this menu and the networking items: [code]/lua/autorun/sv_networking.lua[/code] [code] if (SERVER) then util.AddNetworkString("WinterIsComing") hook.Add("PlayerDeath","Hnaknaw",function(victim, inflictor, attacker) if IsValid( victim ) then -- Make sure the dead player exists net.Start( "WinterIsComing" ) net.WriteEntity( attacker ) net.Send(victim) end end) end net.Receive( "WinterIsComing", function() vgui.Create("CogentDeathScreen") end ) [/code] [code]/lua/autorun/client/cl_death_popup.lua[/code] [code] self[5.1] = vgui.Create('CGTextEntry',self[2]) self[5.1]:SetFont('Cogent24') self[5.1]:SetText("") self[5.1]:SetTextColor(Color(255,20,20)) self[5.1]:SetEditable(false) self[5.1]:SetDisabled(true) net.Receive( "WinterIsComing", function() local ply = net.ReadEntity() if ply:GetClass() == "prop_physics" then local plx = ply:GetModel() self[5.1]:SetText(plx) elseif ply:IsWorld() then self[5.1]:SetText("World") elseif IsValid(ply) then local plx = ply:Nick() local plz = tostring(plx) self[5.1]:SetText(plz) else self[5.1]:SetText("Hnaknaw") end end ) self[5.1]:SetSize(surface.GetTextWidth(self[5.1]:GetText(),self[5.1]:GetFont())+4,30) self[5.1]:SetPos(surface.GetTextWidth(self[5]:GetText(),self[5]:GetFont())+20,130) [/code][B] Any help at all is much appreciated!!! Just a point in the right direction is really all I'm asking for, but if you're able to change the provided code to fix that is also greatly appreciated! [/B]
Well net receivers don't work exactly how you're wanting, unfortunately. Are you at all storing the created panel in a global variable? I'd suggest when the client initially receives the message to create the panel/in the panel's Init() function, do like [code]MYGLOBALPANEL = vgui.Create("CogentDeathScreen") -- or if you choose PANEL:Init() function PANEL:Init() MYGLOBALPANEL = self end[/code] and then your net receiver which handles the text setting could do [code]net.Receive("WinterIsComing", function() local ply = net.ReadEntity() local panel = MYGLOBALPANEL if (!IsValid(panel)) then return end if ply:GetClass() == "prop_physics" then local plx = ply:GetModel() panel[5.1]:SetText(plx) elseif ply:IsWorld() then panel[5.1]:SetText("World") elseif IsValid(ply) then local plx = ply:Nick() local plz = tostring(plx) panel[5.1]:SetText(plz) else panel[5.1]:SetText("Hnaknaw") end end)[/code] Also you have in your sv_networking file a net receiver that creates vgui? That's not right, the server can't create vgui elements.
[QUOTE=Z0mb1n3;52275729]Well net receivers don't work exactly how you're wanting, unfortunately. Are you at all storing the created panel in a global variable? I'd suggest when the client initially receives the message to create the panel/in the panel's Init() function, do like [code]MYGLOBALPANEL = vgui.Create("CogentDeathScreen") -- or if you choose PANEL:Init() function PANEL:Init() MYGLOBALPANEL = self end[/code] and then your net receiver which handles the text setting could do [code]net.Receive("WinterIsComing", function() local ply = net.ReadEntity() local panel = MYGLOBALPANEL if (!IsValid(panel)) then return end if ply:GetClass() == "prop_physics" then local plx = ply:GetModel() panel[5.1]:SetText(plx) elseif ply:IsWorld() then panel[5.1]:SetText("World") elseif IsValid(ply) then local plx = ply:Nick() local plz = tostring(plx) panel[5.1]:SetText(plz) else panel[5.1]:SetText("Hnaknaw") end end)[/code] Also you have in your sv_networking file a net receiver that creates vgui? That's not right, the server can't create vgui elements.[/QUOTE] So I tried the first one by putting the following, and still resulted in an error... Second one also resulted in the same error. Error: [code][ERROR] addons/cogent/lua/autorun/sv_networking.lua:83: attempt to index a nil value 1. func - addons/cogent/lua/autorun/sv_networking.lua:83 2. unknown - lua/includes/extensions/net.lua:32 [/code] CODE: [code]/lua/autorun/sv_networking.lua[/code] [code] net.Receive( "WinterIsComing", function() local ply = net.ReadEntity() MYGLOBALPANEL = vgui.Create("CogentDeathScreen") local panel = MYGLOBALPANEL if (!IsValid(panel)) then return end if ply:GetClass() == "prop_physics" then local plx = ply:GetModel() panel[5.1]:SetText(plx) elseif ply:IsWorld() then panel[5.1]:SetText("World") elseif IsValid(ply) and ply:IsPlayer() then local plx = ply:Nick() local plz = tostring(plx) panel[5.1]:SetText(plz) [B]*Errored line*[/B] else panel[5.1]:SetText("Hnaknaw") end panel[5.1]:SetSize(surface.GetTextWidth(panel[5.1]:GetText(),panel[5.1]:GetFont())+4,30) panel[5.1]:SetPos(surface.GetTextWidth(panel[5]:GetText(),panel[5]:GetFont())+20,130) end ) [/code]
[QUOTE=Richtofen;52275776]So I tried the first one by putting the following, and still resulted in an error... Second one also resulted in the same error. Error: [code][ERROR] addons/cogent/lua/autorun/sv_networking.lua:83: attempt to index a nil value 1. func - addons/cogent/lua/autorun/sv_networking.lua:83 2. unknown - lua/includes/extensions/net.lua:32 [/code] CODE: [code]/lua/autorun/sv_networking.lua[/code] [code] net.Receive( "WinterIsComing", function() local ply = net.ReadEntity() MYGLOBALPANEL = vgui.Create("CogentDeathScreen") local panel = MYGLOBALPANEL if (!IsValid(panel)) then return end if ply:GetClass() == "prop_physics" then local plx = ply:GetModel() panel[5.1]:SetText(plx) elseif ply:IsWorld() then panel[5.1]:SetText("World") elseif IsValid(ply) and ply:IsPlayer() then local plx = ply:Nick() local plz = tostring(plx) panel[5.1]:SetText(plz) [B]*Errored line*[/B] else panel[5.1]:SetText("Hnaknaw") end panel[5.1]:SetSize(surface.GetTextWidth(panel[5.1]:GetText(),panel[5.1]:GetFont())+4,30) panel[5.1]:SetPos(surface.GetTextWidth(panel[5]:GetText(),panel[5]:GetFont())+20,130) end ) [/code][/QUOTE] Well, you're putting that in the wrong file. That should be in your cl_death_popup file. As well, you're creating the panel inside the net receive, so it's no longer necessary to have the MYGLOBALPANEL, instead you can just set [code]local panel = vgui.Create("CogentDeathScreen")[/code] The original error you posted was due to the code trying to set the text of a panel that didn't exist or was invalid, and the second error you're getting now is because you're creating VGUI on the server.
Okay, i've narrowed it down to not picking up the CGTextEntry "panel[5.1]". It won't let me set text because it can't find what "panel is" when it's already localized at the top of the function...? [code] local function PopulateDeathMenu() local ply = net.ReadEntity() local panel = vgui.Create("CogentDeathScreen") panel:SetTitle("Hi :)") if (!IsValid(panel)) then return end if ply:GetClass() == "prop_physics" then local plx = ply:GetModel() panel[5.1]:SetText(plx) elseif ply:IsWorld() then panel[5.1]:SetText("World") elseif IsValid(ply) then local plx = ply:Nick() local plz = tostring(plx) panel[5.1]:SetText("Hi") else panel[5.1]:SetText("Hnaknaw") end panel[5.1]:SetSize(surface.GetTextWidth(panel[5.1]:GetText(),panel[5.1]:GetFont())+4,30) panel[5.1]:SetPos(surface.GetTextWidth(panel[5]:GetText(),panel[5]:GetFont())+20,130) end net.Receive( "WinterIsComing", PopulateDeathMenu) [/code] Now the really weird thing is that I can change the the panel title via: [code] panel:SetTitle("Example")[/code] And I can also change the menu buttons as well [code]self[1]:SetButtonText("Boobies")[/code] [B]Could nested panels be the underlying issue here? EDIT: I will rework my custom vgui element tomorrow and see if that helps with the nested frames. Will report back afterwards :) Thanks for your input! [/B]
Sorry, you need to Log In to post a reply to this thread.