• VGUI Help SetNwString function
    4 replies, posted
Hey all, Just wondering if anyone can point me in the right direction with this, I got this piece of code from the gmod lua wiki, I need to set a strings value when they enter it into a VGUI text box. Well here is the 2 ways Ive tried already: [B]1st try:[/B] Cl_init: [lua] function testpanel() -- Create the function DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 250,250 ) DermaPanel:SetSize( 500, 50 ) DermaPanel:SetTitle( "Derma Testing Stuff" ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetVisible( true ) DermaPanel:MakePopup() DermaText = vgui.Create( "DTextEntry", DermaPanel ) DermaText:SetPos( 20,25 ) DermaText:SetTall( 20 ) DermaText:SetWide( 450 ) DermaText:SetEnterAllowed( true ) DermaText.OnEnter = function() RunConsoleCommand("Ready") DermaPanel:SetVisible( false ) end end concommand.Add("menutest", testpanel) -- adding the console command [/lua] Init: [lua] function Ready( ply ) ply:SetNWString("rpname", DermaText:GetValue()) end concommand.Add( "Ready", Ready ); [/lua] Problem is with this way, is that because its clientside the menu it wont send it serverside. [B]2nd try[/B] [lua] function testpanel() -- Create the function DermaPanel = vgui.Create( "DFrame" ) DermaPanel:SetPos( 250,250 ) DermaPanel:SetSize( 500, 50 ) DermaPanel:SetTitle( "Derma Testing Stuff" ) DermaPanel:ShowCloseButton( true ) DermaPanel:SetVisible( true ) DermaPanel:MakePopup() DermaText = vgui.Create( "DTextEntry", DermaPanel ) DermaText:SetPos( 20,25 ) DermaText:SetTall( 20 ) DermaText:SetWide( 450 ) DermaText:SetEnterAllowed( true ) DermaText.OnEnter = function() SetNWString("rpname", DermaText:GetValue()) DermaPanel:SetVisible( false ) end end concommand.Add("menutest", testpanel) -- adding the console command [/lua] And as you can see its clientside like before, so its not setting it. Does anyone have any idea on how to accomplish this? as its my first time working with VGUI. Thanks for reading
Your first attempt looks correct. Are you sure it is running the console command and the console command is available?
[QUOTE=Overv;20157411]Your first attempt looks correct. Are you sure it is running the console command and the console command is available?[/QUOTE] Well the error I got from the first try was that it gave the error that it didnt know what 'DermaText' is, I wasn't sure how I would carry the information from the VGUI to serverside.
[QUOTE=Dave_Parker;20157520]Replace RunConsoleCommand("Ready") with RunConsoleCommand("Ready", DermaText:GetValue()) and the console command in init with function Ready( ply, _, args ) ply:SetNWString("rpname", args[1]) end concommand.Add( "Ready", Ready ) Keep your first attempt.[/QUOTE] Oh that worked perfect thanks to Dave_Parker and Overv :D
Sorry, you need to Log In to post a reply to this thread.