VGUI Help SetNwString function

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:

1st try:

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.

2nd try

[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?

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.

Replace

RunConsoleCommand(“Ready”)

with

RunConsoleCommand(“Ready”, DermaText:GetValue())

and the console command in init with

[lua]
function Ready( ply, _, args )

ply:SetNWString(“rpname”, args[1])

end

concommand.Add( “Ready”, Ready )
[/lua]

Keep your first attempt.

Oh that worked perfect thanks to Dave_Parker and Overv :smiley: